{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#添加mean, var, quantile0.25, quantile0.75, short_r, long_R 20折 去掉['end_date', 'start_date'] 分层Kfold 0.9030324667306955\n",
    "#线下0.9030324667306955   #换随机种子27 线下0.9030710225394317\n",
    "#线上0.88096              #换随机种子27 线上0.87732\n",
    "\n",
    "\n",
    "#添加mean, var, quantile0.25, quantile0.75, short_r, long_R 20折 去掉['end_date', 'start_date'] 普通Kfold \n",
    "#线下0.9036168785156858\n",
    "#线上<0.88096"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Demo2\n",
    "filename = \"demo2\"\n",
    "#添加mean特征 5折 0.8927776608071499\n",
    "#添加mean特征 5折 去掉['min_speed','mode_direction','start_hour','end_hour', 'work_days','min_direction'] 0.8914638465677877\n",
    "#添加mean特征 5折 去掉['end_date', 'start_date'] 0.8921640788131545\n",
    "#添加mean特征 20折 0.8997570901153127\n",
    "#添加mean特征 20折 去掉['end_date', 'start_date'] 0.8999200076564892\n",
    "#添加mean特征 20折 去掉['end_date', 'start_date', 'work_days', 'min_direction'] 0.8997006697543012\n",
    "#添加mean特征 20折 去掉['end_date', 'start_date'] 普通Kfold 0.9009965767590594\n",
    "#添加mean, var, quantile0.25, quantile0.75 20折 不去掉特征 普通Kfold 0.9018005493147694\n",
    "#添加mean, var, quantile0.25, quantile0.75 20折 去掉['end_date', 'start_date'] 普通Kfold 0.9039271970594686\n",
    "#添加mean, var, quantile0.25, quantile0.75 20折 去掉['end_date', 'start_date'] 分层Kfold 0.9018198605499913\n",
    "#添加mean, var, quantile0.25, quantile0.75, short_r, long_R 20折 去掉['end_date', 'start_date'] 普通Kfold 0.9036168785156858\n",
    "#添加mean, var, quantile0.25, quantile0.75, short_r, long_R 20折 去掉['end_date', 'start_date'] 分层Kfold 0.9030324667306955"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "from tqdm import tqdm\n",
    "import warnings\n",
    "warnings.filterwarnings(\"ignore\")\n",
    "from datetime import datetime\n",
    "#显示所有列\n",
    "pd.set_option('display.max_columns', None)\n",
    "#显示所有行\n",
    "pd.set_option('display.max_rows', None)\n",
    "\n",
    "train_list = os.listdir('../hy_round1_train_20200102/')\n",
    "test_list = os.listdir('../hy_round1_testA_20200102/')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 特征工程"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "def distance(m, n):\n",
    "    \"\"\"calculate Euclidean Distance\"\"\"\n",
    "    return np.sqrt(np.sum((m - n) ** 2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def create_feature_base(demo):\n",
    "    demo.rename(columns={'渔船ID': \"ID\", \"速度\": \"speed\", \"方向\": \"direction\"}, inplace=True)\n",
    "    demo_train = pd.DataFrame()\n",
    "    \n",
    "    #分割time特征得到day, hour, quarter\n",
    "    tmp = pd.DataFrame()\n",
    "    tmp['time'] = pd.to_datetime(demo['time'],format='%m%d %H:%M:%S')\n",
    "    demo[\"month\"] = tmp[\"time\"].dt.month\n",
    "    demo[\"day\"] = tmp[\"time\"].dt.day\n",
    "    demo[\"hour\"] = tmp[\"time\"].dt.hour\n",
    "    del tmp\n",
    "\n",
    "    #按时间排序\n",
    "    demo.sort_values([\"time\"],inplace=True, ascending=False)\n",
    "\n",
    "    #计算作业持续时间\n",
    "    start = demo.iloc[-1]['time']\n",
    "    end = demo.iloc[0]['time']\n",
    "    diff = datetime.strptime(str(end),\"%m%d %H:%M:%S\") - datetime.strptime(str(start),\"%m%d %H:%M:%S\")\n",
    "\n",
    "    #构建时间起始日,小时\n",
    "    demo_train['ID'] = [demo['ID'][0]]\n",
    "    demo_train['start_date'] = int(start[2:4])\n",
    "    demo_train['start_hour'] = int(start[5:7])\n",
    "    demo_train['end_date'] = int(end[2:4])\n",
    "    demo_train['end_hour'] = int(end[5:7])\n",
    "    demo_train['work_days'] = diff.days\n",
    "    demo_train['work_seconds'] = diff.seconds\n",
    "    \n",
    "    #unique, mean, std, var, min, quantile0.25, median, quantile0.75, max, mode特征: 方向, 速度, x, y\n",
    "    for s in ['x', 'y', 'speed', 'direction']:\n",
    "        temp = demo.groupby('ID')[s].agg({\n",
    "                                          'nunique_' + s: 'nunique', \n",
    "                                          'mean_' + s: 'mean', \n",
    "                                          'std_' + s: 'std', \n",
    "                                          'var_' + s: 'var',\n",
    "                                          'min_' + s: 'min',\n",
    "                                          'quantile0.25_' + s: lambda x: x.quantile(0.25),\n",
    "                                          'median_' + s: 'median',\n",
    "                                          'quantile0.75_' + s: lambda x: x.quantile(0.75),\n",
    "                                          'max_' + s: 'max',\n",
    "                                          'mode_' + s: lambda x: np.mean(pd.Series.mode(x))}).reset_index()\n",
    "        demo_train = pd.merge(demo_train,temp, on='ID',how='left')\n",
    "\n",
    "    #构建x,y坐标交互特征\n",
    "    demo_train['x_max-min'] = demo_train['max_x'] - demo_train['min_x']\n",
    "    demo_train['y_max-min'] = demo_train['max_y'] - demo_train['min_y']\n",
    "    demo_train['rec_area'] = demo_train['y_max-min'] * demo_train['x_max-min']\n",
    "    \n",
    "    #活动半径\n",
    "    min_point = np.array([demo_train['min_x'], demo_train['min_y']])\n",
    "    center_point = np.array([demo_train['median_x'], demo_train['median_y']])\n",
    "    max_point = np.array([demo_train['max_x'], demo_train['max_y']])\n",
    "    demo_train['short_r'] = distance(min_point, center_point)\n",
    "    demo_train['long_r'] = distance(max_point, center_point)\n",
    "    \n",
    "    return demo_train"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# #构建训练集特征\n",
    "# train = pd.DataFrame()\n",
    "# for file in tqdm(train_list):\n",
    "#     demo = pd.read_csv('../hy_round1_train_20200102/' + file)\n",
    "#     demo_train = create_feature_base(demo)\n",
    "#     demo_train['type'] = demo['type']\n",
    "#     train = train.append(demo_train)\n",
    "\n",
    "# train.to_csv('../input/train_'+filename+'.csv', index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# #构建测试集\n",
    "# test = pd.DataFrame()\n",
    "# for file in tqdm(test_list):\n",
    "#     demo = pd.read_csv('../hy_round1_testA_20200102/' + file)\n",
    "#     demo_test = create_feature_base(demo)\n",
    "#     test = test.append(demo_test)\n",
    "\n",
    "# test['type'] = '测试'\n",
    "# test.to_csv('../input/test_'+filename+'.csv', index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# #合并数据集合\n",
    "# data = train.append(test).reset_index(drop=True)\n",
    "# data.to_csv('../input/data_'+filename+'.csv', index=False)\n",
    "data = pd.read_csv('../input/data_'+filename+'.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "type\n",
       "刺网    1018\n",
       "围网    1621\n",
       "拖网    4361\n",
       "测试    2000\n",
       "Name: ID, dtype: int64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#数据分布\n",
    "data.groupby('type')['ID'].nunique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "work_days\n",
       "0      28\n",
       "1      42\n",
       "2    8930\n",
       "Name: ID, dtype: int64"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#数据分布\n",
    "data.groupby('work_days')['ID'].nunique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Mem. usage decreased to  1.32 Mb (63.7% reduction)\n"
     ]
    }
   ],
   "source": [
    "#降低内存使用\n",
    "def reduce_mem_usage(df, verbose=True):\n",
    "    numerics = ['int16', 'int32', 'int64', 'float16', 'float32', 'float64']\n",
    "    start_mem = df.memory_usage().sum() / 1024**2    \n",
    "    for col in df.columns:\n",
    "        col_type = df[col].dtypes\n",
    "        if col_type in numerics:\n",
    "            c_min = df[col].min()\n",
    "            c_max = df[col].max()\n",
    "            if str(col_type)[:3] == 'int':\n",
    "                if c_min > np.iinfo(np.int8).min and c_max < np.iinfo(np.int8).max:\n",
    "                    df[col] = df[col].astype(np.int8)\n",
    "                elif c_min > np.iinfo(np.int16).min and c_max < np.iinfo(np.int16).max:\n",
    "                    df[col] = df[col].astype(np.int16)\n",
    "                elif c_min > np.iinfo(np.int32).min and c_max < np.iinfo(np.int32).max:\n",
    "                    df[col] = df[col].astype(np.int32)\n",
    "                elif c_min > np.iinfo(np.int64).min and c_max < np.iinfo(np.int64).max:\n",
    "                    df[col] = df[col].astype(np.int64)  \n",
    "            else:\n",
    "                if c_min > np.finfo(np.float16).min and c_max < np.finfo(np.float16).max:\n",
    "                    df[col] = df[col].astype(np.float16)\n",
    "                elif c_min > np.finfo(np.float32).min and c_max < np.finfo(np.float32).max:\n",
    "                    df[col] = df[col].astype(np.float32)\n",
    "                else:\n",
    "                    df[col] = df[col].astype(np.float64)    \n",
    "    end_mem = df.memory_usage().sum() / 1024**2\n",
    "    if verbose: print('Mem. usage decreased to {:5.2f} Mb ({:.1f}% reduction)'.format(end_mem, 100 * (start_mem - end_mem) / start_mem))\n",
    "    return df\n",
    "\n",
    "data = reduce_mem_usage(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ID</th>\n",
       "      <th>start_date</th>\n",
       "      <th>start_hour</th>\n",
       "      <th>end_date</th>\n",
       "      <th>end_hour</th>\n",
       "      <th>work_days</th>\n",
       "      <th>work_seconds</th>\n",
       "      <th>nunique_x</th>\n",
       "      <th>mean_x</th>\n",
       "      <th>std_x</th>\n",
       "      <th>var_x</th>\n",
       "      <th>min_x</th>\n",
       "      <th>quantile0.25_x</th>\n",
       "      <th>median_x</th>\n",
       "      <th>quantile0.75_x</th>\n",
       "      <th>max_x</th>\n",
       "      <th>mode_x</th>\n",
       "      <th>nunique_y</th>\n",
       "      <th>mean_y</th>\n",
       "      <th>std_y</th>\n",
       "      <th>var_y</th>\n",
       "      <th>min_y</th>\n",
       "      <th>quantile0.25_y</th>\n",
       "      <th>median_y</th>\n",
       "      <th>quantile0.75_y</th>\n",
       "      <th>max_y</th>\n",
       "      <th>mode_y</th>\n",
       "      <th>nunique_speed</th>\n",
       "      <th>mean_speed</th>\n",
       "      <th>std_speed</th>\n",
       "      <th>var_speed</th>\n",
       "      <th>min_speed</th>\n",
       "      <th>quantile0.25_speed</th>\n",
       "      <th>median_speed</th>\n",
       "      <th>quantile0.75_speed</th>\n",
       "      <th>max_speed</th>\n",
       "      <th>mode_speed</th>\n",
       "      <th>nunique_direction</th>\n",
       "      <th>mean_direction</th>\n",
       "      <th>std_direction</th>\n",
       "      <th>var_direction</th>\n",
       "      <th>min_direction</th>\n",
       "      <th>quantile0.25_direction</th>\n",
       "      <th>median_direction</th>\n",
       "      <th>quantile0.75_direction</th>\n",
       "      <th>max_direction</th>\n",
       "      <th>mode_direction</th>\n",
       "      <th>x_max-min</th>\n",
       "      <th>y_max-min</th>\n",
       "      <th>rec_area</th>\n",
       "      <th>short_r</th>\n",
       "      <th>long_r</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>9000.000000</td>\n",
       "      <td>9000.000000</td>\n",
       "      <td>9000.000000</td>\n",
       "      <td>9000.000000</td>\n",
       "      <td>9000.000000</td>\n",
       "      <td>9000.000000</td>\n",
       "      <td>9000.000000</td>\n",
       "      <td>9000.000000</td>\n",
       "      <td>9000.000</td>\n",
       "      <td>9000.000000</td>\n",
       "      <td>9.000000e+03</td>\n",
       "      <td>9.000000e+03</td>\n",
       "      <td>9000.000</td>\n",
       "      <td>9.000000e+03</td>\n",
       "      <td>9000.000</td>\n",
       "      <td>9.000000e+03</td>\n",
       "      <td>9.000000e+03</td>\n",
       "      <td>9000.000000</td>\n",
       "      <td>9.000000e+03</td>\n",
       "      <td>9000.000000</td>\n",
       "      <td>9.000000e+03</td>\n",
       "      <td>9.000000e+03</td>\n",
       "      <td>9.000000e+03</td>\n",
       "      <td>9000.00</td>\n",
       "      <td>9.000000e+03</td>\n",
       "      <td>9.000000e+03</td>\n",
       "      <td>9000.000</td>\n",
       "      <td>9000.000000</td>\n",
       "      <td>9000.000000</td>\n",
       "      <td>9000.000000</td>\n",
       "      <td>9000.000000</td>\n",
       "      <td>9000.000000</td>\n",
       "      <td>9000.000000</td>\n",
       "      <td>9000.000000</td>\n",
       "      <td>9000.000000</td>\n",
       "      <td>9000.000000</td>\n",
       "      <td>9000.000000</td>\n",
       "      <td>9000.000000</td>\n",
       "      <td>9000.00000</td>\n",
       "      <td>9000.0000</td>\n",
       "      <td>9000.0</td>\n",
       "      <td>9000.000000</td>\n",
       "      <td>9000.0</td>\n",
       "      <td>9000.0</td>\n",
       "      <td>9000.0000</td>\n",
       "      <td>9000.000000</td>\n",
       "      <td>9000.0</td>\n",
       "      <td>9.000000e+03</td>\n",
       "      <td>9.000000e+03</td>\n",
       "      <td>9.000000e+03</td>\n",
       "      <td>9.000000e+03</td>\n",
       "      <td>9.000000e+03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>4499.500000</td>\n",
       "      <td>16.735444</td>\n",
       "      <td>6.057778</td>\n",
       "      <td>15.200556</td>\n",
       "      <td>18.421333</td>\n",
       "      <td>1.989111</td>\n",
       "      <td>79754.373778</td>\n",
       "      <td>169.043556</td>\n",
       "      <td>6277192.000</td>\n",
       "      <td>18501.685547</td>\n",
       "      <td>9.269484e+08</td>\n",
       "      <td>6.246707e+06</td>\n",
       "      <td>6263541.000</td>\n",
       "      <td>6.276252e+06</td>\n",
       "      <td>6289299.000</td>\n",
       "      <td>6.311670e+06</td>\n",
       "      <td>6.267595e+06</td>\n",
       "      <td>169.045444</td>\n",
       "      <td>5.271258e+06</td>\n",
       "      <td>15827.667969</td>\n",
       "      <td>6.688265e+08</td>\n",
       "      <td>5.239628e+06</td>\n",
       "      <td>5.260886e+06</td>\n",
       "      <td>5271686.00</td>\n",
       "      <td>5.282714e+06</td>\n",
       "      <td>5.296670e+06</td>\n",
       "      <td>5280384.500</td>\n",
       "      <td>47.948667</td>\n",
       "      <td>1.826172</td>\n",
       "      <td>1.827148</td>\n",
       "      <td>4.367188</td>\n",
       "      <td>0.040314</td>\n",
       "      <td>0.670410</td>\n",
       "      <td>1.381836</td>\n",
       "      <td>2.330078</td>\n",
       "      <td>inf</td>\n",
       "      <td>0.975098</td>\n",
       "      <td>125.743667</td>\n",
       "      <td>inf</td>\n",
       "      <td>inf</td>\n",
       "      <td>inf</td>\n",
       "      <td>1.517556</td>\n",
       "      <td>inf</td>\n",
       "      <td>inf</td>\n",
       "      <td>inf</td>\n",
       "      <td>345.492889</td>\n",
       "      <td>inf</td>\n",
       "      <td>6.498545e+04</td>\n",
       "      <td>5.704316e+04</td>\n",
       "      <td>1.030359e+10</td>\n",
       "      <td>4.939588e+04</td>\n",
       "      <td>4.856018e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>2598.220545</td>\n",
       "      <td>9.017295</td>\n",
       "      <td>6.021058</td>\n",
       "      <td>8.458648</td>\n",
       "      <td>5.843025</td>\n",
       "      <td>0.130363</td>\n",
       "      <td>15043.635727</td>\n",
       "      <td>149.461862</td>\n",
       "      <td>267330.750</td>\n",
       "      <td>24180.638672</td>\n",
       "      <td>3.192541e+09</td>\n",
       "      <td>2.688202e+05</td>\n",
       "      <td>266388.125</td>\n",
       "      <td>2.683973e+05</td>\n",
       "      <td>270577.875</td>\n",
       "      <td>2.719637e+05</td>\n",
       "      <td>2.650859e+05</td>\n",
       "      <td>149.462799</td>\n",
       "      <td>2.539307e+05</td>\n",
       "      <td>20453.837891</td>\n",
       "      <td>2.740022e+09</td>\n",
       "      <td>2.577030e+05</td>\n",
       "      <td>2.536513e+05</td>\n",
       "      <td>254638.75</td>\n",
       "      <td>2.553973e+05</td>\n",
       "      <td>2.619363e+05</td>\n",
       "      <td>251257.125</td>\n",
       "      <td>26.060203</td>\n",
       "      <td>1.403320</td>\n",
       "      <td>1.013672</td>\n",
       "      <td>4.511719</td>\n",
       "      <td>0.312012</td>\n",
       "      <td>1.107422</td>\n",
       "      <td>1.598633</td>\n",
       "      <td>2.140625</td>\n",
       "      <td>6.605469</td>\n",
       "      <td>1.968750</td>\n",
       "      <td>47.762415</td>\n",
       "      <td>51.37500</td>\n",
       "      <td>26.9375</td>\n",
       "      <td>inf</td>\n",
       "      <td>22.264329</td>\n",
       "      <td>inf</td>\n",
       "      <td>inf</td>\n",
       "      <td>82.1875</td>\n",
       "      <td>55.197673</td>\n",
       "      <td>inf</td>\n",
       "      <td>9.392264e+04</td>\n",
       "      <td>9.319413e+04</td>\n",
       "      <td>9.896097e+10</td>\n",
       "      <td>1.003555e+05</td>\n",
       "      <td>6.902297e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>779.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>5157216.000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>5.000250e+06</td>\n",
       "      <td>5145658.500</td>\n",
       "      <td>5.154122e+06</td>\n",
       "      <td>5160097.000</td>\n",
       "      <td>5.171072e+06</td>\n",
       "      <td>5.151852e+06</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>4.558782e+06</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>3.345433e+06</td>\n",
       "      <td>4.534440e+06</td>\n",
       "      <td>4554698.50</td>\n",
       "      <td>4.561156e+06</td>\n",
       "      <td>4.569556e+06</td>\n",
       "      <td>4556533.000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>2249.750000</td>\n",
       "      <td>7.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>11.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>85305.750000</td>\n",
       "      <td>21.000000</td>\n",
       "      <td>6120494.500</td>\n",
       "      <td>1474.436218</td>\n",
       "      <td>2.173964e+06</td>\n",
       "      <td>6.109108e+06</td>\n",
       "      <td>6111773.000</td>\n",
       "      <td>6.118254e+06</td>\n",
       "      <td>6131055.500</td>\n",
       "      <td>6.154110e+06</td>\n",
       "      <td>6.117245e+06</td>\n",
       "      <td>21.000000</td>\n",
       "      <td>5.114761e+06</td>\n",
       "      <td>1578.166077</td>\n",
       "      <td>2.490635e+06</td>\n",
       "      <td>5.097788e+06</td>\n",
       "      <td>5.114660e+06</td>\n",
       "      <td>5114870.00</td>\n",
       "      <td>5.117820e+06</td>\n",
       "      <td>5.130553e+06</td>\n",
       "      <td>5120416.000</td>\n",
       "      <td>21.000000</td>\n",
       "      <td>0.422119</td>\n",
       "      <td>1.073242</td>\n",
       "      <td>1.151367</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.109985</td>\n",
       "      <td>0.219971</td>\n",
       "      <td>8.578125</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>111.000000</td>\n",
       "      <td>92.93750</td>\n",
       "      <td>100.4375</td>\n",
       "      <td>10094.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>30.0</td>\n",
       "      <td>166.9375</td>\n",
       "      <td>356.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.016174e+04</td>\n",
       "      <td>1.039761e+04</td>\n",
       "      <td>1.644373e+08</td>\n",
       "      <td>3.250371e+03</td>\n",
       "      <td>3.906232e+03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>4499.500000</td>\n",
       "      <td>15.500000</td>\n",
       "      <td>12.000000</td>\n",
       "      <td>13.000000</td>\n",
       "      <td>23.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>85605.000000</td>\n",
       "      <td>147.000000</td>\n",
       "      <td>6246626.250</td>\n",
       "      <td>11680.274414</td>\n",
       "      <td>1.364288e+08</td>\n",
       "      <td>6.236778e+06</td>\n",
       "      <td>6246221.500</td>\n",
       "      <td>6.246524e+06</td>\n",
       "      <td>6246626.000</td>\n",
       "      <td>6.260713e+06</td>\n",
       "      <td>6.246328e+06</td>\n",
       "      <td>147.000000</td>\n",
       "      <td>5.225667e+06</td>\n",
       "      <td>9897.690918</td>\n",
       "      <td>9.796429e+07</td>\n",
       "      <td>5.201684e+06</td>\n",
       "      <td>5.220735e+06</td>\n",
       "      <td>5230049.75</td>\n",
       "      <td>5.241042e+06</td>\n",
       "      <td>5.242020e+06</td>\n",
       "      <td>5241040.500</td>\n",
       "      <td>54.000000</td>\n",
       "      <td>1.661621</td>\n",
       "      <td>1.966309</td>\n",
       "      <td>3.866211</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.109985</td>\n",
       "      <td>0.320068</td>\n",
       "      <td>2.210938</td>\n",
       "      <td>10.093750</td>\n",
       "      <td>0.109985</td>\n",
       "      <td>134.000000</td>\n",
       "      <td>123.68750</td>\n",
       "      <td>109.5625</td>\n",
       "      <td>12008.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>97.0</td>\n",
       "      <td>217.8750</td>\n",
       "      <td>358.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4.496924e+04</td>\n",
       "      <td>3.913814e+04</td>\n",
       "      <td>1.896339e+09</td>\n",
       "      <td>3.117227e+04</td>\n",
       "      <td>3.464828e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>6749.250000</td>\n",
       "      <td>28.000000</td>\n",
       "      <td>12.000000</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>23.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>85921.000000</td>\n",
       "      <td>293.000000</td>\n",
       "      <td>6372105.375</td>\n",
       "      <td>25215.867188</td>\n",
       "      <td>6.358400e+08</td>\n",
       "      <td>6.356861e+06</td>\n",
       "      <td>6359236.000</td>\n",
       "      <td>6.365318e+06</td>\n",
       "      <td>6389842.625</td>\n",
       "      <td>6.412199e+06</td>\n",
       "      <td>6.359136e+06</td>\n",
       "      <td>293.000000</td>\n",
       "      <td>5.384598e+06</td>\n",
       "      <td>21177.854004</td>\n",
       "      <td>4.485016e+08</td>\n",
       "      <td>5.354363e+06</td>\n",
       "      <td>5.373603e+06</td>\n",
       "      <td>5383127.00</td>\n",
       "      <td>5.404607e+06</td>\n",
       "      <td>5.409410e+06</td>\n",
       "      <td>5402255.250</td>\n",
       "      <td>69.000000</td>\n",
       "      <td>2.955078</td>\n",
       "      <td>2.541016</td>\n",
       "      <td>6.460938</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.489990</td>\n",
       "      <td>2.910156</td>\n",
       "      <td>3.990234</td>\n",
       "      <td>10.093750</td>\n",
       "      <td>0.320068</td>\n",
       "      <td>154.000000</td>\n",
       "      <td>150.78125</td>\n",
       "      <td>116.5625</td>\n",
       "      <td>13584.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>40.0</td>\n",
       "      <td>154.0</td>\n",
       "      <td>246.0000</td>\n",
       "      <td>360.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>8.521579e+04</td>\n",
       "      <td>7.594669e+04</td>\n",
       "      <td>5.558854e+09</td>\n",
       "      <td>6.203469e+04</td>\n",
       "      <td>6.299710e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>8999.000000</td>\n",
       "      <td>31.000000</td>\n",
       "      <td>23.000000</td>\n",
       "      <td>30.000000</td>\n",
       "      <td>23.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>86387.000000</td>\n",
       "      <td>3064.000000</td>\n",
       "      <td>7106512.500</td>\n",
       "      <td>280971.562500</td>\n",
       "      <td>7.894503e+10</td>\n",
       "      <td>7.091534e+06</td>\n",
       "      <td>7113146.500</td>\n",
       "      <td>7.114756e+06</td>\n",
       "      <td>7118826.500</td>\n",
       "      <td>7.133786e+06</td>\n",
       "      <td>7.115142e+06</td>\n",
       "      <td>3064.000000</td>\n",
       "      <td>6.723456e+06</td>\n",
       "      <td>356946.968750</td>\n",
       "      <td>1.274111e+11</td>\n",
       "      <td>6.627580e+06</td>\n",
       "      <td>6.722882e+06</td>\n",
       "      <td>6738740.50</td>\n",
       "      <td>6.741522e+06</td>\n",
       "      <td>7.667580e+06</td>\n",
       "      <td>6687567.500</td>\n",
       "      <td>114.000000</td>\n",
       "      <td>9.703125</td>\n",
       "      <td>15.257812</td>\n",
       "      <td>232.750000</td>\n",
       "      <td>9.703125</td>\n",
       "      <td>9.703125</td>\n",
       "      <td>10.093750</td>\n",
       "      <td>10.203125</td>\n",
       "      <td>100.187500</td>\n",
       "      <td>10.093750</td>\n",
       "      <td>359.000000</td>\n",
       "      <td>360.00000</td>\n",
       "      <td>164.3750</td>\n",
       "      <td>27040.0</td>\n",
       "      <td>360.000000</td>\n",
       "      <td>360.0</td>\n",
       "      <td>360.0</td>\n",
       "      <td>360.0000</td>\n",
       "      <td>360.000000</td>\n",
       "      <td>360.0</td>\n",
       "      <td>2.066366e+06</td>\n",
       "      <td>3.423408e+06</td>\n",
       "      <td>4.797482e+12</td>\n",
       "      <td>3.067378e+06</td>\n",
       "      <td>1.561612e+06</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                ID   start_date   start_hour     end_date     end_hour  \\\n",
       "count  9000.000000  9000.000000  9000.000000  9000.000000  9000.000000   \n",
       "mean   4499.500000    16.735444     6.057778    15.200556    18.421333   \n",
       "std    2598.220545     9.017295     6.021058     8.458648     5.843025   \n",
       "min       0.000000     1.000000     0.000000     2.000000     0.000000   \n",
       "25%    2249.750000     7.000000     0.000000     6.000000    11.000000   \n",
       "50%    4499.500000    15.500000    12.000000    13.000000    23.000000   \n",
       "75%    6749.250000    28.000000    12.000000    20.000000    23.000000   \n",
       "max    8999.000000    31.000000    23.000000    30.000000    23.000000   \n",
       "\n",
       "         work_days  work_seconds    nunique_x       mean_x          std_x  \\\n",
       "count  9000.000000   9000.000000  9000.000000     9000.000    9000.000000   \n",
       "mean      1.989111  79754.373778   169.043556  6277192.000   18501.685547   \n",
       "std       0.130363  15043.635727   149.461862   267330.750   24180.638672   \n",
       "min       0.000000    779.000000     1.000000  5157216.000       0.000000   \n",
       "25%       2.000000  85305.750000    21.000000  6120494.500    1474.436218   \n",
       "50%       2.000000  85605.000000   147.000000  6246626.250   11680.274414   \n",
       "75%       2.000000  85921.000000   293.000000  6372105.375   25215.867188   \n",
       "max       2.000000  86387.000000  3064.000000  7106512.500  280971.562500   \n",
       "\n",
       "              var_x         min_x  quantile0.25_x      median_x  \\\n",
       "count  9.000000e+03  9.000000e+03        9000.000  9.000000e+03   \n",
       "mean   9.269484e+08  6.246707e+06     6263541.000  6.276252e+06   \n",
       "std    3.192541e+09  2.688202e+05      266388.125  2.683973e+05   \n",
       "min    0.000000e+00  5.000250e+06     5145658.500  5.154122e+06   \n",
       "25%    2.173964e+06  6.109108e+06     6111773.000  6.118254e+06   \n",
       "50%    1.364288e+08  6.236778e+06     6246221.500  6.246524e+06   \n",
       "75%    6.358400e+08  6.356861e+06     6359236.000  6.365318e+06   \n",
       "max    7.894503e+10  7.091534e+06     7113146.500  7.114756e+06   \n",
       "\n",
       "       quantile0.75_x         max_x        mode_x    nunique_y        mean_y  \\\n",
       "count        9000.000  9.000000e+03  9.000000e+03  9000.000000  9.000000e+03   \n",
       "mean      6289299.000  6.311670e+06  6.267595e+06   169.045444  5.271258e+06   \n",
       "std        270577.875  2.719637e+05  2.650859e+05   149.462799  2.539307e+05   \n",
       "min       5160097.000  5.171072e+06  5.151852e+06     1.000000  4.558782e+06   \n",
       "25%       6131055.500  6.154110e+06  6.117245e+06    21.000000  5.114761e+06   \n",
       "50%       6246626.000  6.260713e+06  6.246328e+06   147.000000  5.225667e+06   \n",
       "75%       6389842.625  6.412199e+06  6.359136e+06   293.000000  5.384598e+06   \n",
       "max       7118826.500  7.133786e+06  7.115142e+06  3064.000000  6.723456e+06   \n",
       "\n",
       "               std_y         var_y         min_y  quantile0.25_y    median_y  \\\n",
       "count    9000.000000  9.000000e+03  9.000000e+03    9.000000e+03     9000.00   \n",
       "mean    15827.667969  6.688265e+08  5.239628e+06    5.260886e+06  5271686.00   \n",
       "std     20453.837891  2.740022e+09  2.577030e+05    2.536513e+05   254638.75   \n",
       "min         0.000000  0.000000e+00  3.345433e+06    4.534440e+06  4554698.50   \n",
       "25%      1578.166077  2.490635e+06  5.097788e+06    5.114660e+06  5114870.00   \n",
       "50%      9897.690918  9.796429e+07  5.201684e+06    5.220735e+06  5230049.75   \n",
       "75%     21177.854004  4.485016e+08  5.354363e+06    5.373603e+06  5383127.00   \n",
       "max    356946.968750  1.274111e+11  6.627580e+06    6.722882e+06  6738740.50   \n",
       "\n",
       "       quantile0.75_y         max_y       mode_y  nunique_speed   mean_speed  \\\n",
       "count    9.000000e+03  9.000000e+03     9000.000    9000.000000  9000.000000   \n",
       "mean     5.282714e+06  5.296670e+06  5280384.500      47.948667     1.826172   \n",
       "std      2.553973e+05  2.619363e+05   251257.125      26.060203     1.403320   \n",
       "min      4.561156e+06  4.569556e+06  4556533.000       1.000000     0.000000   \n",
       "25%      5.117820e+06  5.130553e+06  5120416.000      21.000000     0.422119   \n",
       "50%      5.241042e+06  5.242020e+06  5241040.500      54.000000     1.661621   \n",
       "75%      5.404607e+06  5.409410e+06  5402255.250      69.000000     2.955078   \n",
       "max      6.741522e+06  7.667580e+06  6687567.500     114.000000     9.703125   \n",
       "\n",
       "         std_speed    var_speed    min_speed  quantile0.25_speed  \\\n",
       "count  9000.000000  9000.000000  9000.000000         9000.000000   \n",
       "mean      1.827148     4.367188     0.040314            0.670410   \n",
       "std       1.013672     4.511719     0.312012            1.107422   \n",
       "min       0.000000     0.000000     0.000000            0.000000   \n",
       "25%       1.073242     1.151367     0.000000            0.000000   \n",
       "50%       1.966309     3.866211     0.000000            0.109985   \n",
       "75%       2.541016     6.460938     0.000000            0.489990   \n",
       "max      15.257812   232.750000     9.703125            9.703125   \n",
       "\n",
       "       median_speed  quantile0.75_speed    max_speed   mode_speed  \\\n",
       "count   9000.000000         9000.000000  9000.000000  9000.000000   \n",
       "mean       1.381836            2.330078          inf     0.975098   \n",
       "std        1.598633            2.140625     6.605469     1.968750   \n",
       "min        0.000000            0.000000     0.000000     0.000000   \n",
       "25%        0.109985            0.219971     8.578125     0.000000   \n",
       "50%        0.320068            2.210938    10.093750     0.109985   \n",
       "75%        2.910156            3.990234    10.093750     0.320068   \n",
       "max       10.093750           10.203125   100.187500    10.093750   \n",
       "\n",
       "       nunique_direction  mean_direction  std_direction  var_direction  \\\n",
       "count        9000.000000      9000.00000      9000.0000         9000.0   \n",
       "mean          125.743667             inf            inf            inf   \n",
       "std            47.762415        51.37500        26.9375            inf   \n",
       "min             1.000000         0.00000         0.0000            0.0   \n",
       "25%           111.000000        92.93750       100.4375        10094.0   \n",
       "50%           134.000000       123.68750       109.5625        12008.0   \n",
       "75%           154.000000       150.78125       116.5625        13584.0   \n",
       "max           359.000000       360.00000       164.3750        27040.0   \n",
       "\n",
       "       min_direction  quantile0.25_direction  median_direction  \\\n",
       "count    9000.000000                  9000.0            9000.0   \n",
       "mean        1.517556                     inf               inf   \n",
       "std        22.264329                     inf               inf   \n",
       "min         0.000000                     0.0               0.0   \n",
       "25%         0.000000                     0.0              30.0   \n",
       "50%         0.000000                     0.0              97.0   \n",
       "75%         0.000000                    40.0             154.0   \n",
       "max       360.000000                   360.0             360.0   \n",
       "\n",
       "       quantile0.75_direction  max_direction  mode_direction     x_max-min  \\\n",
       "count               9000.0000    9000.000000          9000.0  9.000000e+03   \n",
       "mean                      inf     345.492889             inf  6.498545e+04   \n",
       "std                   82.1875      55.197673             inf  9.392264e+04   \n",
       "min                    0.0000       0.000000             0.0  0.000000e+00   \n",
       "25%                  166.9375     356.000000             0.0  1.016174e+04   \n",
       "50%                  217.8750     358.000000             0.0  4.496924e+04   \n",
       "75%                  246.0000     360.000000             0.0  8.521579e+04   \n",
       "max                  360.0000     360.000000           360.0  2.066366e+06   \n",
       "\n",
       "          y_max-min      rec_area       short_r        long_r  \n",
       "count  9.000000e+03  9.000000e+03  9.000000e+03  9.000000e+03  \n",
       "mean   5.704316e+04  1.030359e+10  4.939588e+04  4.856018e+04  \n",
       "std    9.319413e+04  9.896097e+10  1.003555e+05  6.902297e+04  \n",
       "min    0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00  \n",
       "25%    1.039761e+04  1.644373e+08  3.250371e+03  3.906232e+03  \n",
       "50%    3.913814e+04  1.896339e+09  3.117227e+04  3.464828e+04  \n",
       "75%    7.594669e+04  5.558854e+09  6.203469e+04  6.299710e+04  \n",
       "max    3.423408e+06  4.797482e+12  3.067378e+06  1.561612e+06  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.describe()\n",
    "#mode_direction, "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['ID', 'start_date', 'start_hour', 'end_date', 'end_hour', 'work_days',\n",
       "       'work_seconds', 'nunique_x', 'mean_x', 'std_x', 'var_x', 'min_x',\n",
       "       'quantile0.25_x', 'median_x', 'quantile0.75_x', 'max_x', 'mode_x',\n",
       "       'nunique_y', 'mean_y', 'std_y', 'var_y', 'min_y', 'quantile0.25_y',\n",
       "       'median_y', 'quantile0.75_y', 'max_y', 'mode_y', 'nunique_speed',\n",
       "       'mean_speed', 'std_speed', 'var_speed', 'min_speed',\n",
       "       'quantile0.25_speed', 'median_speed', 'quantile0.75_speed', 'max_speed',\n",
       "       'mode_speed', 'nunique_direction', 'mean_direction', 'std_direction',\n",
       "       'var_direction', 'min_direction', 'quantile0.25_direction',\n",
       "       'median_direction', 'quantile0.75_direction', 'max_direction',\n",
       "       'mode_direction', 'x_max-min', 'y_max-min', 'rec_area', 'short_r',\n",
       "       'long_r', 'type'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#所有特征\n",
    "data.columns"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 模型训练"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.model_selection import KFold\n",
    "from sklearn.metrics import confusion_matrix\n",
    "from sklearn.model_selection import StratifiedKFold\n",
    "import lightgbm as lgb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "#设置去掉的特征\n",
    "NotimportantFeats = ['end_date', 'start_date']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "#分离训练集和测试集\n",
    "train = data[data.type!=\"测试\"]\n",
    "test = data[data.type==\"测试\"]\n",
    "\n",
    "#特征选择,X,y分离\n",
    "train_x = train[[i for i in train.columns if i not in ['ID', 'time', 'type']+NotimportantFeats]]\n",
    "test_x = test[[i for i in test.columns if i not in ['ID', 'time', 'type']+NotimportantFeats]]\n",
    "\n",
    "train_y = train['type']\n",
    "\n",
    "#label和type互相装化\n",
    "label2type = dict(zip(range(0, len(set(train_y))), sorted(list(set(train_y)))))\n",
    "type2label = dict(zip(sorted(list(set(train_y))), range(0, len(set(train_y)))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 163,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "cv_pred = []\n",
    "cms = np.zeros((len(set(train_y)),len(set(train_y))))   #混淆矩阵\n",
    "oof = train[['ID']]\n",
    "skf = StratifiedKFold(n_splits=20, random_state=27, shuffle=True)\n",
    "# skf = KFold(n_splits=20, shuffle=True, random_state=27)\n",
    "\n",
    "feature_importances = pd.DataFrame()\n",
    "feature_importances['feature'] = train_x.columns\n",
    "\n",
    "for index, (train_index, val_index) in enumerate(skf.split(train_x, train_y)):\n",
    "    \n",
    "    model = lgb.LGBMClassifier(\n",
    "        boosting_type=\"gbdt\", num_leaves=120, reg_alpha=0, reg_lambda=0.,\n",
    "        max_depth=-1, n_estimators=800, objective='multiclass', class_weight='balanced',\n",
    "        subsample=0.9, colsample_bytree=0.5, subsample_freq=1,\n",
    "        learning_rate=0.03, random_state=2018 + index, n_jobs=10, metric=\"None\", importance_type='gain'\n",
    "    )\n",
    "    \n",
    "    train_x1, val_x1, train_y1, val_y1 = \\\n",
    "    train_x.loc[train_index], train_x.loc[val_index], train_y.loc[train_index], train_y.loc[val_index]\n",
    "\n",
    "    model.fit(train_x1, train_y1)\n",
    "    \n",
    "    #out of folder预测\n",
    "    oof.loc[val_index] = model.predict(val_x1).reshape(-1, 1)\n",
    "    \n",
    "    # Confusion matrix by folds\n",
    "    cms += confusion_matrix(train_y.loc[val_index], oof.loc[val_index])\n",
    "    \n",
    "    #测试集预测\n",
    "    test_y = model.predict(test_x)\n",
    "    test_y = pd.Series(test_y).map(type2label)\n",
    "    \n",
    "    #特征重要性\n",
    "    feature_importances['fold_{}'.format(index + 1)] = model.feature_importances_\n",
    "    \n",
    "    if index == 0:\n",
    "        cv_pred = np.array(test_y).reshape(-1, 1)\n",
    "    else:\n",
    "        cv_pred = np.hstack((cv_pred, np.array(test_y).reshape(-1, 1)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 164,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9030710225394317"
      ]
     },
     "execution_count": 164,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#oof F1-score\n",
    "from sklearn.metrics import f1_score\n",
    "f1_score(y_true=train[['type']], y_pred=oof, average='macro')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 贝叶斯调参"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "from bayes_opt import BayesianOptimization\n",
    "from sklearn.model_selection import train_test_split"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "train_df = train\n",
    "train_y = train\n",
    "test_df = test\n",
    "target = 'type'\n",
    "\n",
    "bayesian_tr_idx, bayesian_val_idx = train_test_split(train_df, test_size = 0.3, random_state = 42, stratify =train_df[target] )\n",
    "bayesian_tr_idx = bayesian_tr_idx.index\n",
    "bayesian_val_idx = bayesian_val_idx.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "def LGB_bayesian(\n",
    "    #learning_rate,\n",
    "    num_leaves, \n",
    "    bagging_fraction,\n",
    "    feature_fraction,\n",
    "    min_child_weight, \n",
    "    min_data_in_leaf,\n",
    "    max_depth,\n",
    "    reg_alpha,\n",
    "    reg_lambda\n",
    "     ):\n",
    "    \n",
    "    # LightGBM expects next three parameters need to be integer. \n",
    "    num_leaves = int(num_leaves)\n",
    "    min_data_in_leaf = int(min_data_in_leaf)\n",
    "    max_depth = int(max_depth)\n",
    "\n",
    "    assert type(num_leaves) == int\n",
    "    assert type(min_data_in_leaf) == int\n",
    "    assert type(max_depth) == int\n",
    "    \n",
    "\n",
    "    param = {\n",
    "              'num_leaves': num_leaves, \n",
    "              'min_data_in_leaf': min_data_in_leaf,\n",
    "              'min_child_weight': min_child_weight,\n",
    "              'bagging_fraction' : bagging_fraction,\n",
    "              'feature_fraction' : feature_fraction,\n",
    "              #'learning_rate' : learning_rate,\n",
    "              'max_depth': max_depth,\n",
    "              'reg_alpha': reg_alpha,\n",
    "              'reg_lambda': reg_lambda,\n",
    "              'objective': 'binary',\n",
    "              'save_binary': True,\n",
    "              'seed': 1337,\n",
    "              'feature_fraction_seed': 1337,\n",
    "              'bagging_seed': 1337,\n",
    "              'drop_seed': 1337,\n",
    "              'data_random_seed': 1337,\n",
    "              'boosting_type': 'gbdt',\n",
    "              'verbose': 1,\n",
    "              'is_unbalance': False,\n",
    "              'boost_from_average': True,\n",
    "              'metric':'auc'}    \n",
    "    \n",
    "    oof = np.zeros(len(train_df))\n",
    "    trn_data= lgb.Dataset(train_df.iloc[bayesian_tr_idx][features].values, label=train_df.iloc[bayesian_tr_idx][target].values)\n",
    "    val_data= lgb.Dataset(train_df.iloc[bayesian_val_idx][features].values, label=train_df.iloc[bayesian_val_idx][target].values)\n",
    "\n",
    "    clf = lgb.train(param, trn_data,  num_boost_round=50, valid_sets = [trn_data, val_data], verbose_eval=0, early_stopping_rounds = 50)\n",
    "    \n",
    "    oof[bayesian_val_idx]  = clf.predict(train_df.iloc[bayesian_val_idx][features].values, num_iteration=clf.best_iteration)  \n",
    "    \n",
    "    score = roc_auc_score(train_df.iloc[bayesian_val_idx][target].values, oof[bayesian_val_idx])\n",
    "\n",
    "    return score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "bounds_LGB = {\n",
    "    'num_leaves': (31, 500), \n",
    "    'min_data_in_leaf': (20, 200),\n",
    "    'bagging_fraction' : (0.1, 0.9),\n",
    "    'feature_fraction' : (0.1, 0.9),\n",
    "    #'learning_rate': (0.01, 0.3),\n",
    "    'min_child_weight': (0.00001, 0.01),   \n",
    "    'reg_alpha': (1, 2), \n",
    "    'reg_lambda': (1, 2),\n",
    "    'max_depth':(-1,50),\n",
    "}\n",
    "LGB_BO = BayesianOptimization(LGB_bayesian, bounds_LGB, random_state=42)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "----------------------------------------------------------------------------------------------------------------------------------\n",
      "|   iter    |  target   | baggin... | featur... | max_depth | min_ch... | min_da... | num_le... | reg_alpha | reg_la... |\n",
      "-------------------------------------------------------------------------------------------------------------------------\n"
     ]
    },
    {
     "ename": "NameError",
     "evalue": "name 'features' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[0;32m~/anaconda3/envs/fastai/lib/python3.7/site-packages/bayes_opt/target_space.py\u001b[0m in \u001b[0;36mprobe\u001b[0;34m(self, params)\u001b[0m\n\u001b[1;32m    190\u001b[0m         \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 191\u001b[0;31m             \u001b[0mtarget\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_cache\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0m_hashable\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    192\u001b[0m         \u001b[0;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mKeyError\u001b[0m: (0.39963209507789, 0.8605714451279329, 36.33169103238166, 0.005990598257128396, 48.083355279638575, 104.16143003767904, 1.0580836121681996, 1.866176145774935)",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-20-96c42e52e258>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m      5\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mwarnings\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcatch_warnings\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      6\u001b[0m     \u001b[0mwarnings\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfilterwarnings\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'ignore'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m     \u001b[0mLGB_BO\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmaximize\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minit_points\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0minit_points\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mn_iter\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mn_iter\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0macq\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'ucb'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mxi\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0.0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0malpha\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m1e-6\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      8\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      9\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mLGB_BO\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mspace\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mkeys\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/envs/fastai/lib/python3.7/site-packages/bayes_opt/bayesian_optimization.py\u001b[0m in \u001b[0;36mmaximize\u001b[0;34m(self, init_points, n_iter, acq, kappa, xi, **gp_params)\u001b[0m\n\u001b[1;32m    172\u001b[0m                 \u001b[0miteration\u001b[0m \u001b[0;34m+=\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    173\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 174\u001b[0;31m             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprobe\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx_probe\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlazy\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mFalse\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    175\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    176\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdispatch\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mEvents\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mOPTMIZATION_END\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/envs/fastai/lib/python3.7/site-packages/bayes_opt/bayesian_optimization.py\u001b[0m in \u001b[0;36mprobe\u001b[0;34m(self, params, lazy)\u001b[0m\n\u001b[1;32m    110\u001b[0m             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_queue\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0madd\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mparams\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    111\u001b[0m         \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 112\u001b[0;31m             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_space\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprobe\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mparams\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    113\u001b[0m             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdispatch\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mEvents\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mOPTMIZATION_STEP\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    114\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m~/anaconda3/envs/fastai/lib/python3.7/site-packages/bayes_opt/target_space.py\u001b[0m in \u001b[0;36mprobe\u001b[0;34m(self, params)\u001b[0m\n\u001b[1;32m    192\u001b[0m         \u001b[0;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    193\u001b[0m             \u001b[0mparams\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mzip\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_keys\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 194\u001b[0;31m             \u001b[0mtarget\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtarget_func\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0mparams\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    195\u001b[0m             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mregister\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtarget\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    196\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mtarget\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m<ipython-input-18-9af36d164416>\u001b[0m in \u001b[0;36mLGB_bayesian\u001b[0;34m(num_leaves, bagging_fraction, feature_fraction, min_child_weight, min_data_in_leaf, max_depth, reg_alpha, reg_lambda)\u001b[0m\n\u001b[1;32m     45\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     46\u001b[0m     \u001b[0moof\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mzeros\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtrain_df\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 47\u001b[0;31m     \u001b[0mtrn_data\u001b[0m\u001b[0;34m=\u001b[0m \u001b[0mlgb\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mDataset\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtrain_df\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0miloc\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mbayesian_tr_idx\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mfeatures\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlabel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtrain_df\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0miloc\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mbayesian_tr_idx\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mtarget\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     48\u001b[0m     \u001b[0mval_data\u001b[0m\u001b[0;34m=\u001b[0m \u001b[0mlgb\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mDataset\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtrain_df\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0miloc\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mbayesian_val_idx\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mfeatures\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlabel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtrain_df\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0miloc\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mbayesian_val_idx\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mtarget\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     49\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mNameError\u001b[0m: name 'features' is not defined"
     ]
    }
   ],
   "source": [
    "init_points = 10\n",
    "n_iter = 15\n",
    "print('-' * 130)\n",
    "\n",
    "with warnings.catch_warnings():\n",
    "    warnings.filterwarnings('ignore')\n",
    "    LGB_BO.maximize(init_points=init_points, n_iter=n_iter, acq='ucb', xi=0.0, alpha=1e-6)\n",
    "\n",
    "print(LGB_BO.space.keys)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "LGB_BO.max['params']\n",
    "\n",
    "param_lgb = {\n",
    "        'min_data_in_leaf': int(LGB_BO.max['params']['min_data_in_leaf']), \n",
    "        'num_leaves': int(LGB_BO.max['params']['num_leaves']), \n",
    "        #'learning_rate': LGB_BO.max['params']['learning_rate'],\n",
    "        'min_child_weight': LGB_BO.max['params']['min_child_weight'],\n",
    "        'bagging_fraction': LGB_BO.max['params']['bagging_fraction'], \n",
    "        'feature_fraction': LGB_BO.max['params']['feature_fraction'],\n",
    "        'reg_lambda': LGB_BO.max['params']['reg_lambda'],\n",
    "        'reg_alpha': LGB_BO.max['params']['reg_alpha'],\n",
    "        'max_depth': int(LGB_BO.max['params']['max_depth']), \n",
    "        'objective': 'binary',\n",
    "        'save_binary': True,\n",
    "        'seed': 1337,\n",
    "        'feature_fraction_seed': 1337,\n",
    "        'bagging_seed': 1337,\n",
    "        'drop_seed': 1337,\n",
    "        'data_random_seed': 1337,\n",
    "        'boosting_type': 'gbdt',\n",
    "        'verbose': 1,\n",
    "        'is_unbalance': False,\n",
    "        'boost_from_average': True,\n",
    "        'metric':'auc'\n",
    "    }"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 特征重要性分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 165,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>feature</th>\n",
       "      <th>fold_1</th>\n",
       "      <th>fold_2</th>\n",
       "      <th>fold_3</th>\n",
       "      <th>fold_4</th>\n",
       "      <th>fold_5</th>\n",
       "      <th>fold_6</th>\n",
       "      <th>fold_7</th>\n",
       "      <th>fold_8</th>\n",
       "      <th>fold_9</th>\n",
       "      <th>fold_10</th>\n",
       "      <th>fold_11</th>\n",
       "      <th>fold_12</th>\n",
       "      <th>fold_13</th>\n",
       "      <th>fold_14</th>\n",
       "      <th>fold_15</th>\n",
       "      <th>fold_16</th>\n",
       "      <th>fold_17</th>\n",
       "      <th>fold_18</th>\n",
       "      <th>fold_19</th>\n",
       "      <th>fold_20</th>\n",
       "      <th>importance</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>mean_y</td>\n",
       "      <td>19221.398269</td>\n",
       "      <td>14860.651262</td>\n",
       "      <td>18962.502916</td>\n",
       "      <td>18740.124450</td>\n",
       "      <td>16064.771306</td>\n",
       "      <td>15829.119294</td>\n",
       "      <td>14643.601725</td>\n",
       "      <td>19059.471628</td>\n",
       "      <td>19220.391557</td>\n",
       "      <td>18907.175236</td>\n",
       "      <td>22768.783831</td>\n",
       "      <td>13362.105250</td>\n",
       "      <td>20717.132446</td>\n",
       "      <td>15412.060062</td>\n",
       "      <td>18132.757549</td>\n",
       "      <td>14357.078150</td>\n",
       "      <td>16131.053514</td>\n",
       "      <td>14225.209955</td>\n",
       "      <td>18949.921438</td>\n",
       "      <td>17959.295079</td>\n",
       "      <td>347524.604919</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>rec_area</td>\n",
       "      <td>16148.206796</td>\n",
       "      <td>14624.937866</td>\n",
       "      <td>17591.453751</td>\n",
       "      <td>14430.403987</td>\n",
       "      <td>20363.762647</td>\n",
       "      <td>14372.920567</td>\n",
       "      <td>16812.335265</td>\n",
       "      <td>15148.821619</td>\n",
       "      <td>10093.961091</td>\n",
       "      <td>14215.497438</td>\n",
       "      <td>16127.728835</td>\n",
       "      <td>15941.528779</td>\n",
       "      <td>16185.780214</td>\n",
       "      <td>14364.157745</td>\n",
       "      <td>18263.158126</td>\n",
       "      <td>15755.966707</td>\n",
       "      <td>16738.530806</td>\n",
       "      <td>13690.274764</td>\n",
       "      <td>13328.244559</td>\n",
       "      <td>18088.551947</td>\n",
       "      <td>312286.223509</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>min_y</td>\n",
       "      <td>16284.547346</td>\n",
       "      <td>14276.602778</td>\n",
       "      <td>11824.852361</td>\n",
       "      <td>13728.388969</td>\n",
       "      <td>11861.664052</td>\n",
       "      <td>11971.266402</td>\n",
       "      <td>13923.519162</td>\n",
       "      <td>12121.415867</td>\n",
       "      <td>11115.969459</td>\n",
       "      <td>16374.271555</td>\n",
       "      <td>13822.706458</td>\n",
       "      <td>13983.270410</td>\n",
       "      <td>13717.698755</td>\n",
       "      <td>11954.141218</td>\n",
       "      <td>15572.038331</td>\n",
       "      <td>13169.232998</td>\n",
       "      <td>15972.488351</td>\n",
       "      <td>12181.050149</td>\n",
       "      <td>14749.631402</td>\n",
       "      <td>14921.924357</td>\n",
       "      <td>273526.680381</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>mode_y</td>\n",
       "      <td>14243.235564</td>\n",
       "      <td>12418.091071</td>\n",
       "      <td>12022.121917</td>\n",
       "      <td>13743.854767</td>\n",
       "      <td>16278.695224</td>\n",
       "      <td>13677.028194</td>\n",
       "      <td>12072.493242</td>\n",
       "      <td>12569.084161</td>\n",
       "      <td>9054.122054</td>\n",
       "      <td>13618.216230</td>\n",
       "      <td>7770.789793</td>\n",
       "      <td>15906.485680</td>\n",
       "      <td>15011.499135</td>\n",
       "      <td>12242.712079</td>\n",
       "      <td>12351.150072</td>\n",
       "      <td>15816.506679</td>\n",
       "      <td>12944.195955</td>\n",
       "      <td>9756.646410</td>\n",
       "      <td>15072.394317</td>\n",
       "      <td>13075.354771</td>\n",
       "      <td>259644.677316</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>quantile0.25_y</td>\n",
       "      <td>8752.418362</td>\n",
       "      <td>11042.226662</td>\n",
       "      <td>9393.385079</td>\n",
       "      <td>10301.746808</td>\n",
       "      <td>9757.164566</td>\n",
       "      <td>9910.222850</td>\n",
       "      <td>10033.151751</td>\n",
       "      <td>10317.644056</td>\n",
       "      <td>10942.663947</td>\n",
       "      <td>9528.274919</td>\n",
       "      <td>10532.972345</td>\n",
       "      <td>9036.922916</td>\n",
       "      <td>8125.848018</td>\n",
       "      <td>11397.262519</td>\n",
       "      <td>7700.081598</td>\n",
       "      <td>9817.452248</td>\n",
       "      <td>9872.390371</td>\n",
       "      <td>10180.992647</td>\n",
       "      <td>7367.890286</td>\n",
       "      <td>7511.275000</td>\n",
       "      <td>191521.986946</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>quantile0.75_y</td>\n",
       "      <td>6075.619293</td>\n",
       "      <td>10397.332364</td>\n",
       "      <td>10132.542047</td>\n",
       "      <td>8243.777216</td>\n",
       "      <td>11644.253813</td>\n",
       "      <td>11660.845931</td>\n",
       "      <td>5791.399894</td>\n",
       "      <td>9812.241145</td>\n",
       "      <td>9499.975248</td>\n",
       "      <td>8212.246772</td>\n",
       "      <td>9613.107066</td>\n",
       "      <td>8280.914361</td>\n",
       "      <td>6463.666502</td>\n",
       "      <td>10150.285330</td>\n",
       "      <td>9349.578912</td>\n",
       "      <td>8743.799586</td>\n",
       "      <td>10094.495908</td>\n",
       "      <td>11550.560815</td>\n",
       "      <td>6821.680726</td>\n",
       "      <td>9105.177010</td>\n",
       "      <td>181643.499938</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>max_y</td>\n",
       "      <td>7538.338491</td>\n",
       "      <td>8852.231422</td>\n",
       "      <td>9608.756342</td>\n",
       "      <td>8773.654795</td>\n",
       "      <td>7743.373998</td>\n",
       "      <td>8690.681684</td>\n",
       "      <td>11767.799492</td>\n",
       "      <td>7076.907906</td>\n",
       "      <td>9858.986677</td>\n",
       "      <td>7961.105068</td>\n",
       "      <td>6230.416604</td>\n",
       "      <td>12278.629486</td>\n",
       "      <td>7357.656086</td>\n",
       "      <td>14054.804534</td>\n",
       "      <td>10386.944431</td>\n",
       "      <td>9044.114166</td>\n",
       "      <td>6993.588445</td>\n",
       "      <td>11768.278314</td>\n",
       "      <td>7035.937205</td>\n",
       "      <td>6844.425595</td>\n",
       "      <td>179866.630740</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>median_y</td>\n",
       "      <td>7909.615636</td>\n",
       "      <td>8371.098699</td>\n",
       "      <td>9620.838026</td>\n",
       "      <td>6741.385773</td>\n",
       "      <td>7759.759096</td>\n",
       "      <td>8630.769950</td>\n",
       "      <td>13771.608113</td>\n",
       "      <td>8909.147251</td>\n",
       "      <td>9415.607567</td>\n",
       "      <td>6356.340772</td>\n",
       "      <td>9479.282575</td>\n",
       "      <td>8204.065982</td>\n",
       "      <td>9556.946169</td>\n",
       "      <td>6610.683051</td>\n",
       "      <td>8762.884358</td>\n",
       "      <td>8557.135417</td>\n",
       "      <td>8461.190984</td>\n",
       "      <td>9256.224817</td>\n",
       "      <td>9386.376649</td>\n",
       "      <td>11216.928896</td>\n",
       "      <td>176977.889781</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>x_max-min</td>\n",
       "      <td>6342.740038</td>\n",
       "      <td>7107.348223</td>\n",
       "      <td>6685.151519</td>\n",
       "      <td>6489.086805</td>\n",
       "      <td>6702.366397</td>\n",
       "      <td>7337.931113</td>\n",
       "      <td>7392.554086</td>\n",
       "      <td>8640.621680</td>\n",
       "      <td>10726.021291</td>\n",
       "      <td>7710.675483</td>\n",
       "      <td>6922.813522</td>\n",
       "      <td>6299.975754</td>\n",
       "      <td>5634.520681</td>\n",
       "      <td>9408.699651</td>\n",
       "      <td>7338.287897</td>\n",
       "      <td>7021.278338</td>\n",
       "      <td>7430.697060</td>\n",
       "      <td>8032.359884</td>\n",
       "      <td>8006.215924</td>\n",
       "      <td>7319.645719</td>\n",
       "      <td>148548.991065</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>quantile0.75_speed</td>\n",
       "      <td>6020.706322</td>\n",
       "      <td>7530.480071</td>\n",
       "      <td>6843.415336</td>\n",
       "      <td>6496.333151</td>\n",
       "      <td>6779.809631</td>\n",
       "      <td>6852.707523</td>\n",
       "      <td>6714.041764</td>\n",
       "      <td>7693.192412</td>\n",
       "      <td>6162.554779</td>\n",
       "      <td>7507.526844</td>\n",
       "      <td>6770.741541</td>\n",
       "      <td>7159.534025</td>\n",
       "      <td>7383.349319</td>\n",
       "      <td>7429.278060</td>\n",
       "      <td>6142.983239</td>\n",
       "      <td>6307.850238</td>\n",
       "      <td>7802.956958</td>\n",
       "      <td>6621.741121</td>\n",
       "      <td>7315.837474</td>\n",
       "      <td>7689.653699</td>\n",
       "      <td>139224.693506</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>mode_x</td>\n",
       "      <td>7489.565976</td>\n",
       "      <td>5981.012177</td>\n",
       "      <td>6017.147762</td>\n",
       "      <td>6602.321351</td>\n",
       "      <td>5864.167275</td>\n",
       "      <td>6190.778440</td>\n",
       "      <td>6628.186016</td>\n",
       "      <td>6557.119543</td>\n",
       "      <td>5898.282436</td>\n",
       "      <td>7432.459709</td>\n",
       "      <td>6499.282744</td>\n",
       "      <td>7112.727436</td>\n",
       "      <td>7033.599487</td>\n",
       "      <td>6552.546623</td>\n",
       "      <td>5741.005855</td>\n",
       "      <td>6809.196062</td>\n",
       "      <td>7826.107415</td>\n",
       "      <td>5974.635742</td>\n",
       "      <td>7849.353640</td>\n",
       "      <td>7542.144354</td>\n",
       "      <td>133601.640043</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>quantile0.25_x</td>\n",
       "      <td>6237.476178</td>\n",
       "      <td>6792.530535</td>\n",
       "      <td>5978.948015</td>\n",
       "      <td>6439.180881</td>\n",
       "      <td>6230.616480</td>\n",
       "      <td>6242.351307</td>\n",
       "      <td>6320.322816</td>\n",
       "      <td>6752.132912</td>\n",
       "      <td>7377.456655</td>\n",
       "      <td>6138.372222</td>\n",
       "      <td>7525.964950</td>\n",
       "      <td>5887.438601</td>\n",
       "      <td>6125.348468</td>\n",
       "      <td>6010.735019</td>\n",
       "      <td>7402.675412</td>\n",
       "      <td>7260.485944</td>\n",
       "      <td>6044.042175</td>\n",
       "      <td>6903.171291</td>\n",
       "      <td>5822.463126</td>\n",
       "      <td>6886.417008</td>\n",
       "      <td>130378.129994</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>y_max-min</td>\n",
       "      <td>7701.180483</td>\n",
       "      <td>7015.441758</td>\n",
       "      <td>4979.721939</td>\n",
       "      <td>6828.259983</td>\n",
       "      <td>4791.700611</td>\n",
       "      <td>7861.716167</td>\n",
       "      <td>5560.153491</td>\n",
       "      <td>4762.732641</td>\n",
       "      <td>7348.800399</td>\n",
       "      <td>4100.586790</td>\n",
       "      <td>7325.501805</td>\n",
       "      <td>6596.057998</td>\n",
       "      <td>5863.783078</td>\n",
       "      <td>6536.727297</td>\n",
       "      <td>5825.743214</td>\n",
       "      <td>6647.009286</td>\n",
       "      <td>5979.615541</td>\n",
       "      <td>7270.051269</td>\n",
       "      <td>6247.824854</td>\n",
       "      <td>4215.546815</td>\n",
       "      <td>123458.155420</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>min_x</td>\n",
       "      <td>6136.728355</td>\n",
       "      <td>6750.891677</td>\n",
       "      <td>6568.348090</td>\n",
       "      <td>6144.177516</td>\n",
       "      <td>6169.750059</td>\n",
       "      <td>7110.626756</td>\n",
       "      <td>6144.022576</td>\n",
       "      <td>6379.234759</td>\n",
       "      <td>6665.300104</td>\n",
       "      <td>5710.194495</td>\n",
       "      <td>5919.809751</td>\n",
       "      <td>6309.866828</td>\n",
       "      <td>5823.464620</td>\n",
       "      <td>6015.045934</td>\n",
       "      <td>6310.960961</td>\n",
       "      <td>6017.172016</td>\n",
       "      <td>5876.697282</td>\n",
       "      <td>6278.309280</td>\n",
       "      <td>5388.811534</td>\n",
       "      <td>5423.793193</td>\n",
       "      <td>123143.205787</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>median_speed</td>\n",
       "      <td>5596.520980</td>\n",
       "      <td>6126.377436</td>\n",
       "      <td>5932.755266</td>\n",
       "      <td>5772.127061</td>\n",
       "      <td>5386.196575</td>\n",
       "      <td>5790.936010</td>\n",
       "      <td>5726.561054</td>\n",
       "      <td>5712.461555</td>\n",
       "      <td>6542.476148</td>\n",
       "      <td>6056.271817</td>\n",
       "      <td>6070.806043</td>\n",
       "      <td>5291.572735</td>\n",
       "      <td>6306.944462</td>\n",
       "      <td>5987.531710</td>\n",
       "      <td>5789.582407</td>\n",
       "      <td>5613.650844</td>\n",
       "      <td>5006.616581</td>\n",
       "      <td>5745.779769</td>\n",
       "      <td>6002.184760</td>\n",
       "      <td>5840.165143</td>\n",
       "      <td>116297.518356</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>max_x</td>\n",
       "      <td>5444.983737</td>\n",
       "      <td>5362.822399</td>\n",
       "      <td>4658.839087</td>\n",
       "      <td>5339.069990</td>\n",
       "      <td>4244.938606</td>\n",
       "      <td>5602.335646</td>\n",
       "      <td>4507.169634</td>\n",
       "      <td>4780.218619</td>\n",
       "      <td>5098.489258</td>\n",
       "      <td>5837.771945</td>\n",
       "      <td>3575.658281</td>\n",
       "      <td>4247.691465</td>\n",
       "      <td>4899.092854</td>\n",
       "      <td>5639.182695</td>\n",
       "      <td>5680.992464</td>\n",
       "      <td>4273.834286</td>\n",
       "      <td>6169.282135</td>\n",
       "      <td>5556.057816</td>\n",
       "      <td>4980.503252</td>\n",
       "      <td>4606.847297</td>\n",
       "      <td>100505.781466</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>median_x</td>\n",
       "      <td>4917.096823</td>\n",
       "      <td>4762.720295</td>\n",
       "      <td>4761.238827</td>\n",
       "      <td>5105.808038</td>\n",
       "      <td>5879.714240</td>\n",
       "      <td>5009.585700</td>\n",
       "      <td>4277.149047</td>\n",
       "      <td>4766.156113</td>\n",
       "      <td>5188.487060</td>\n",
       "      <td>4011.815637</td>\n",
       "      <td>5340.900547</td>\n",
       "      <td>5233.782840</td>\n",
       "      <td>5274.654882</td>\n",
       "      <td>4491.051563</td>\n",
       "      <td>4881.292127</td>\n",
       "      <td>5807.160314</td>\n",
       "      <td>4529.264288</td>\n",
       "      <td>5503.335942</td>\n",
       "      <td>5940.142820</td>\n",
       "      <td>4029.915400</td>\n",
       "      <td>99711.272504</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>std_speed</td>\n",
       "      <td>5371.017475</td>\n",
       "      <td>4607.418630</td>\n",
       "      <td>4274.091468</td>\n",
       "      <td>4771.584780</td>\n",
       "      <td>4928.447696</td>\n",
       "      <td>5664.363051</td>\n",
       "      <td>5288.767392</td>\n",
       "      <td>4646.308638</td>\n",
       "      <td>4892.011369</td>\n",
       "      <td>4872.977195</td>\n",
       "      <td>5150.068955</td>\n",
       "      <td>5736.877106</td>\n",
       "      <td>4433.948052</td>\n",
       "      <td>4612.147752</td>\n",
       "      <td>4952.727953</td>\n",
       "      <td>4493.533755</td>\n",
       "      <td>4828.241296</td>\n",
       "      <td>4832.819964</td>\n",
       "      <td>4681.385145</td>\n",
       "      <td>4810.684742</td>\n",
       "      <td>97849.422413</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>std_y</td>\n",
       "      <td>4106.819497</td>\n",
       "      <td>4353.975603</td>\n",
       "      <td>3781.728841</td>\n",
       "      <td>5018.746880</td>\n",
       "      <td>4298.233037</td>\n",
       "      <td>5229.044141</td>\n",
       "      <td>5888.575181</td>\n",
       "      <td>5444.958164</td>\n",
       "      <td>4923.330188</td>\n",
       "      <td>5878.412545</td>\n",
       "      <td>3221.847193</td>\n",
       "      <td>5429.656796</td>\n",
       "      <td>5820.838737</td>\n",
       "      <td>4044.069201</td>\n",
       "      <td>3767.843959</td>\n",
       "      <td>4651.530424</td>\n",
       "      <td>4538.891367</td>\n",
       "      <td>6042.356184</td>\n",
       "      <td>7170.819490</td>\n",
       "      <td>3028.979388</td>\n",
       "      <td>96640.656814</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>nunique_direction</td>\n",
       "      <td>4613.376105</td>\n",
       "      <td>4812.708549</td>\n",
       "      <td>4420.698851</td>\n",
       "      <td>4838.367382</td>\n",
       "      <td>4070.509273</td>\n",
       "      <td>4766.322734</td>\n",
       "      <td>4753.447203</td>\n",
       "      <td>4619.496169</td>\n",
       "      <td>4973.611914</td>\n",
       "      <td>4557.087668</td>\n",
       "      <td>4825.594258</td>\n",
       "      <td>4988.241249</td>\n",
       "      <td>4255.202262</td>\n",
       "      <td>5025.045166</td>\n",
       "      <td>4307.181990</td>\n",
       "      <td>5005.232801</td>\n",
       "      <td>4488.435013</td>\n",
       "      <td>4994.210842</td>\n",
       "      <td>4576.711529</td>\n",
       "      <td>4563.491455</td>\n",
       "      <td>93454.972410</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>mean_x</td>\n",
       "      <td>5233.628455</td>\n",
       "      <td>4709.286984</td>\n",
       "      <td>5510.496624</td>\n",
       "      <td>5079.473171</td>\n",
       "      <td>4422.662868</td>\n",
       "      <td>4392.881409</td>\n",
       "      <td>4614.913392</td>\n",
       "      <td>4274.149223</td>\n",
       "      <td>4619.674106</td>\n",
       "      <td>4671.836065</td>\n",
       "      <td>4923.838008</td>\n",
       "      <td>4861.315224</td>\n",
       "      <td>4108.480129</td>\n",
       "      <td>3813.747782</td>\n",
       "      <td>3664.791033</td>\n",
       "      <td>4105.334844</td>\n",
       "      <td>4972.660301</td>\n",
       "      <td>4165.869482</td>\n",
       "      <td>4943.636102</td>\n",
       "      <td>5021.909314</td>\n",
       "      <td>92110.584513</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>quantile0.75_x</td>\n",
       "      <td>3953.246604</td>\n",
       "      <td>4288.925463</td>\n",
       "      <td>3787.020570</td>\n",
       "      <td>4656.425009</td>\n",
       "      <td>4640.036751</td>\n",
       "      <td>4062.536589</td>\n",
       "      <td>3824.764374</td>\n",
       "      <td>4541.005955</td>\n",
       "      <td>4837.935149</td>\n",
       "      <td>4666.870425</td>\n",
       "      <td>4389.777884</td>\n",
       "      <td>3752.735032</td>\n",
       "      <td>4766.758192</td>\n",
       "      <td>4963.888117</td>\n",
       "      <td>3494.570440</td>\n",
       "      <td>4761.220887</td>\n",
       "      <td>3247.339275</td>\n",
       "      <td>4586.739466</td>\n",
       "      <td>3821.290833</td>\n",
       "      <td>5032.774015</td>\n",
       "      <td>86075.861029</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>short_r</td>\n",
       "      <td>3373.485201</td>\n",
       "      <td>3623.217322</td>\n",
       "      <td>4390.631377</td>\n",
       "      <td>4070.365015</td>\n",
       "      <td>4561.858317</td>\n",
       "      <td>4061.768717</td>\n",
       "      <td>4105.460567</td>\n",
       "      <td>3917.113082</td>\n",
       "      <td>5331.023129</td>\n",
       "      <td>4165.795555</td>\n",
       "      <td>3961.757058</td>\n",
       "      <td>3892.548725</td>\n",
       "      <td>4001.802667</td>\n",
       "      <td>4030.984821</td>\n",
       "      <td>4035.829349</td>\n",
       "      <td>3960.724818</td>\n",
       "      <td>3713.429572</td>\n",
       "      <td>4019.502079</td>\n",
       "      <td>3902.511237</td>\n",
       "      <td>3349.462622</td>\n",
       "      <td>80469.271228</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>48</th>\n",
       "      <td>long_r</td>\n",
       "      <td>3647.314546</td>\n",
       "      <td>4030.420573</td>\n",
       "      <td>3832.270661</td>\n",
       "      <td>4097.307802</td>\n",
       "      <td>3430.549941</td>\n",
       "      <td>3395.159435</td>\n",
       "      <td>3708.116055</td>\n",
       "      <td>4129.041123</td>\n",
       "      <td>4043.938609</td>\n",
       "      <td>5135.184760</td>\n",
       "      <td>3847.820889</td>\n",
       "      <td>4233.901501</td>\n",
       "      <td>4188.840190</td>\n",
       "      <td>3380.788650</td>\n",
       "      <td>3416.731911</td>\n",
       "      <td>4471.965511</td>\n",
       "      <td>4596.110208</td>\n",
       "      <td>3859.619137</td>\n",
       "      <td>3595.862345</td>\n",
       "      <td>3618.829447</td>\n",
       "      <td>78659.773295</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>var_speed</td>\n",
       "      <td>3480.240342</td>\n",
       "      <td>3629.876909</td>\n",
       "      <td>4246.701165</td>\n",
       "      <td>3992.951837</td>\n",
       "      <td>3225.283808</td>\n",
       "      <td>3016.552031</td>\n",
       "      <td>3389.525165</td>\n",
       "      <td>3834.116966</td>\n",
       "      <td>3238.870922</td>\n",
       "      <td>3556.896721</td>\n",
       "      <td>3332.906741</td>\n",
       "      <td>4403.268924</td>\n",
       "      <td>3968.402835</td>\n",
       "      <td>3721.163911</td>\n",
       "      <td>3829.276306</td>\n",
       "      <td>3431.717232</td>\n",
       "      <td>3134.958234</td>\n",
       "      <td>4440.574301</td>\n",
       "      <td>4177.322925</td>\n",
       "      <td>4368.016906</td>\n",
       "      <td>74418.624182</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>mean_direction</td>\n",
       "      <td>3434.123785</td>\n",
       "      <td>3551.141563</td>\n",
       "      <td>3616.772221</td>\n",
       "      <td>3137.117174</td>\n",
       "      <td>3325.055924</td>\n",
       "      <td>3352.412915</td>\n",
       "      <td>3262.453490</td>\n",
       "      <td>3411.605538</td>\n",
       "      <td>3544.490806</td>\n",
       "      <td>3336.431234</td>\n",
       "      <td>3646.296857</td>\n",
       "      <td>3018.330051</td>\n",
       "      <td>3562.101904</td>\n",
       "      <td>3216.504201</td>\n",
       "      <td>3203.040713</td>\n",
       "      <td>3172.409158</td>\n",
       "      <td>3314.408409</td>\n",
       "      <td>3125.365224</td>\n",
       "      <td>3615.632190</td>\n",
       "      <td>3345.370991</td>\n",
       "      <td>67191.064348</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>nunique_x</td>\n",
       "      <td>3250.615875</td>\n",
       "      <td>3368.575973</td>\n",
       "      <td>3569.579478</td>\n",
       "      <td>3576.186530</td>\n",
       "      <td>3226.801451</td>\n",
       "      <td>3584.189530</td>\n",
       "      <td>3015.056711</td>\n",
       "      <td>3478.292025</td>\n",
       "      <td>3475.652348</td>\n",
       "      <td>3295.418592</td>\n",
       "      <td>3056.181372</td>\n",
       "      <td>3131.639666</td>\n",
       "      <td>3492.966779</td>\n",
       "      <td>2731.642838</td>\n",
       "      <td>3477.105487</td>\n",
       "      <td>3522.261010</td>\n",
       "      <td>3574.411092</td>\n",
       "      <td>3216.194085</td>\n",
       "      <td>3239.925103</td>\n",
       "      <td>3583.364864</td>\n",
       "      <td>66866.060809</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>std_x</td>\n",
       "      <td>2764.143472</td>\n",
       "      <td>3303.925002</td>\n",
       "      <td>3275.394201</td>\n",
       "      <td>2842.450496</td>\n",
       "      <td>2995.352464</td>\n",
       "      <td>2658.187859</td>\n",
       "      <td>3309.645727</td>\n",
       "      <td>3043.520326</td>\n",
       "      <td>2957.962580</td>\n",
       "      <td>3092.647234</td>\n",
       "      <td>3670.153818</td>\n",
       "      <td>2872.652138</td>\n",
       "      <td>3094.026340</td>\n",
       "      <td>3000.678668</td>\n",
       "      <td>3747.655587</td>\n",
       "      <td>3435.756100</td>\n",
       "      <td>2931.367602</td>\n",
       "      <td>3013.391407</td>\n",
       "      <td>3207.703943</td>\n",
       "      <td>2904.176704</td>\n",
       "      <td>62120.791667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>nunique_speed</td>\n",
       "      <td>3144.553005</td>\n",
       "      <td>2586.216252</td>\n",
       "      <td>2867.756464</td>\n",
       "      <td>3033.233907</td>\n",
       "      <td>3344.704223</td>\n",
       "      <td>2811.057011</td>\n",
       "      <td>2851.163932</td>\n",
       "      <td>3469.899103</td>\n",
       "      <td>2639.104191</td>\n",
       "      <td>2956.480185</td>\n",
       "      <td>3012.789462</td>\n",
       "      <td>3128.888741</td>\n",
       "      <td>3083.397729</td>\n",
       "      <td>3394.117942</td>\n",
       "      <td>3076.607195</td>\n",
       "      <td>3073.557331</td>\n",
       "      <td>2921.273090</td>\n",
       "      <td>3135.721985</td>\n",
       "      <td>3026.648647</td>\n",
       "      <td>2783.914212</td>\n",
       "      <td>60341.084606</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>work_seconds</td>\n",
       "      <td>2883.292266</td>\n",
       "      <td>2938.462654</td>\n",
       "      <td>3034.911438</td>\n",
       "      <td>2779.552637</td>\n",
       "      <td>2985.616945</td>\n",
       "      <td>2874.812872</td>\n",
       "      <td>3185.932938</td>\n",
       "      <td>3064.172367</td>\n",
       "      <td>3066.513438</td>\n",
       "      <td>2815.307183</td>\n",
       "      <td>2932.914103</td>\n",
       "      <td>2754.064598</td>\n",
       "      <td>2850.194614</td>\n",
       "      <td>2759.144754</td>\n",
       "      <td>2844.696748</td>\n",
       "      <td>2850.358745</td>\n",
       "      <td>2861.042388</td>\n",
       "      <td>2670.687298</td>\n",
       "      <td>2917.383128</td>\n",
       "      <td>2816.664931</td>\n",
       "      <td>57885.726044</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>quantile0.75_direction</td>\n",
       "      <td>2988.695180</td>\n",
       "      <td>2872.318968</td>\n",
       "      <td>2495.881197</td>\n",
       "      <td>3134.841245</td>\n",
       "      <td>2636.155692</td>\n",
       "      <td>2788.405260</td>\n",
       "      <td>2394.613832</td>\n",
       "      <td>2748.632388</td>\n",
       "      <td>2809.864794</td>\n",
       "      <td>2986.432662</td>\n",
       "      <td>2802.381491</td>\n",
       "      <td>2928.465170</td>\n",
       "      <td>3072.117707</td>\n",
       "      <td>2717.107565</td>\n",
       "      <td>2884.510980</td>\n",
       "      <td>2898.809423</td>\n",
       "      <td>3170.038454</td>\n",
       "      <td>2844.801728</td>\n",
       "      <td>2800.362294</td>\n",
       "      <td>2723.824411</td>\n",
       "      <td>56698.260445</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>max_speed</td>\n",
       "      <td>2710.086216</td>\n",
       "      <td>2601.140528</td>\n",
       "      <td>2570.657652</td>\n",
       "      <td>2846.872172</td>\n",
       "      <td>2622.440194</td>\n",
       "      <td>2681.799321</td>\n",
       "      <td>2817.005785</td>\n",
       "      <td>2685.144706</td>\n",
       "      <td>2353.869498</td>\n",
       "      <td>2608.549061</td>\n",
       "      <td>2622.193070</td>\n",
       "      <td>2560.998042</td>\n",
       "      <td>2705.537846</td>\n",
       "      <td>2973.308424</td>\n",
       "      <td>2674.703581</td>\n",
       "      <td>2929.943658</td>\n",
       "      <td>2771.789661</td>\n",
       "      <td>2294.952996</td>\n",
       "      <td>2832.764646</td>\n",
       "      <td>2679.069385</td>\n",
       "      <td>53542.826441</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>mean_speed</td>\n",
       "      <td>2867.696547</td>\n",
       "      <td>2574.062843</td>\n",
       "      <td>2294.608297</td>\n",
       "      <td>2472.872087</td>\n",
       "      <td>2331.352989</td>\n",
       "      <td>2664.881953</td>\n",
       "      <td>2647.635642</td>\n",
       "      <td>2469.498175</td>\n",
       "      <td>2428.629190</td>\n",
       "      <td>2364.523276</td>\n",
       "      <td>2492.599495</td>\n",
       "      <td>2371.829634</td>\n",
       "      <td>2626.113960</td>\n",
       "      <td>2620.586293</td>\n",
       "      <td>2540.634811</td>\n",
       "      <td>2354.461126</td>\n",
       "      <td>2356.248281</td>\n",
       "      <td>2501.276690</td>\n",
       "      <td>2502.790651</td>\n",
       "      <td>2671.879712</td>\n",
       "      <td>50154.181652</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>var_y</td>\n",
       "      <td>2967.159824</td>\n",
       "      <td>2415.903710</td>\n",
       "      <td>3565.047327</td>\n",
       "      <td>2575.951206</td>\n",
       "      <td>1550.853741</td>\n",
       "      <td>1608.613683</td>\n",
       "      <td>1814.634462</td>\n",
       "      <td>2523.740648</td>\n",
       "      <td>2465.660272</td>\n",
       "      <td>2210.519442</td>\n",
       "      <td>3259.763836</td>\n",
       "      <td>1802.444003</td>\n",
       "      <td>1901.253924</td>\n",
       "      <td>2005.892018</td>\n",
       "      <td>1383.743518</td>\n",
       "      <td>2653.610326</td>\n",
       "      <td>2353.463178</td>\n",
       "      <td>2218.921993</td>\n",
       "      <td>2230.952595</td>\n",
       "      <td>2722.145142</td>\n",
       "      <td>46230.274847</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>std_direction</td>\n",
       "      <td>2471.721913</td>\n",
       "      <td>2270.827548</td>\n",
       "      <td>2229.525009</td>\n",
       "      <td>2262.762096</td>\n",
       "      <td>2232.254713</td>\n",
       "      <td>2400.236356</td>\n",
       "      <td>2160.623399</td>\n",
       "      <td>2447.827208</td>\n",
       "      <td>2158.416797</td>\n",
       "      <td>2115.478504</td>\n",
       "      <td>2218.454371</td>\n",
       "      <td>2453.766945</td>\n",
       "      <td>2329.622222</td>\n",
       "      <td>2317.674479</td>\n",
       "      <td>2508.857475</td>\n",
       "      <td>2249.989114</td>\n",
       "      <td>2034.669956</td>\n",
       "      <td>2245.553846</td>\n",
       "      <td>2151.759388</td>\n",
       "      <td>2157.388158</td>\n",
       "      <td>45417.409499</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>median_direction</td>\n",
       "      <td>2215.969911</td>\n",
       "      <td>2131.537246</td>\n",
       "      <td>2031.313835</td>\n",
       "      <td>2110.706139</td>\n",
       "      <td>2022.628224</td>\n",
       "      <td>2112.166212</td>\n",
       "      <td>2099.945034</td>\n",
       "      <td>1966.265977</td>\n",
       "      <td>2045.043413</td>\n",
       "      <td>2032.264054</td>\n",
       "      <td>1905.752172</td>\n",
       "      <td>2152.513408</td>\n",
       "      <td>1870.592374</td>\n",
       "      <td>2116.245086</td>\n",
       "      <td>2096.200213</td>\n",
       "      <td>2048.873735</td>\n",
       "      <td>2040.028182</td>\n",
       "      <td>2273.373324</td>\n",
       "      <td>1809.552658</td>\n",
       "      <td>2301.965619</td>\n",
       "      <td>41382.936815</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>mode_speed</td>\n",
       "      <td>1911.059255</td>\n",
       "      <td>1764.637195</td>\n",
       "      <td>1831.833440</td>\n",
       "      <td>1897.971950</td>\n",
       "      <td>1944.318107</td>\n",
       "      <td>1835.272233</td>\n",
       "      <td>1913.931482</td>\n",
       "      <td>1803.280317</td>\n",
       "      <td>1893.956273</td>\n",
       "      <td>1905.202804</td>\n",
       "      <td>1750.462897</td>\n",
       "      <td>1881.669068</td>\n",
       "      <td>1796.612452</td>\n",
       "      <td>1602.763286</td>\n",
       "      <td>1739.450006</td>\n",
       "      <td>1973.866690</td>\n",
       "      <td>2017.343105</td>\n",
       "      <td>1983.783619</td>\n",
       "      <td>1892.509751</td>\n",
       "      <td>2014.210035</td>\n",
       "      <td>37354.133964</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>quantile0.25_speed</td>\n",
       "      <td>1617.720344</td>\n",
       "      <td>1834.582400</td>\n",
       "      <td>1794.922871</td>\n",
       "      <td>1676.673212</td>\n",
       "      <td>1799.878702</td>\n",
       "      <td>1926.412536</td>\n",
       "      <td>1870.098693</td>\n",
       "      <td>1715.121722</td>\n",
       "      <td>1886.736387</td>\n",
       "      <td>1855.301220</td>\n",
       "      <td>1850.186606</td>\n",
       "      <td>1604.645197</td>\n",
       "      <td>1793.787791</td>\n",
       "      <td>1574.623400</td>\n",
       "      <td>1568.130046</td>\n",
       "      <td>2076.063536</td>\n",
       "      <td>1456.512684</td>\n",
       "      <td>1736.126246</td>\n",
       "      <td>1670.183395</td>\n",
       "      <td>1570.754896</td>\n",
       "      <td>34878.461885</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>nunique_y</td>\n",
       "      <td>1450.760873</td>\n",
       "      <td>1876.786577</td>\n",
       "      <td>1698.356090</td>\n",
       "      <td>1775.311685</td>\n",
       "      <td>1859.571262</td>\n",
       "      <td>1929.057665</td>\n",
       "      <td>1826.406534</td>\n",
       "      <td>1213.983079</td>\n",
       "      <td>1711.705474</td>\n",
       "      <td>1603.780799</td>\n",
       "      <td>1334.876210</td>\n",
       "      <td>1605.519021</td>\n",
       "      <td>1507.037705</td>\n",
       "      <td>1757.717653</td>\n",
       "      <td>1759.637455</td>\n",
       "      <td>2013.877045</td>\n",
       "      <td>1422.531158</td>\n",
       "      <td>1795.152181</td>\n",
       "      <td>1510.560309</td>\n",
       "      <td>2165.986406</td>\n",
       "      <td>33818.615181</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>var_x</td>\n",
       "      <td>1720.477449</td>\n",
       "      <td>1648.562638</td>\n",
       "      <td>1445.212246</td>\n",
       "      <td>1696.401233</td>\n",
       "      <td>1337.635802</td>\n",
       "      <td>1605.835699</td>\n",
       "      <td>1317.102904</td>\n",
       "      <td>1767.773950</td>\n",
       "      <td>1663.034179</td>\n",
       "      <td>1957.063299</td>\n",
       "      <td>1525.435207</td>\n",
       "      <td>1523.418578</td>\n",
       "      <td>1283.888964</td>\n",
       "      <td>1518.160794</td>\n",
       "      <td>1554.616567</td>\n",
       "      <td>1470.336309</td>\n",
       "      <td>1497.242814</td>\n",
       "      <td>1546.934406</td>\n",
       "      <td>1636.483177</td>\n",
       "      <td>2088.758599</td>\n",
       "      <td>31804.374812</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>var_direction</td>\n",
       "      <td>1456.635612</td>\n",
       "      <td>1503.958023</td>\n",
       "      <td>1520.379117</td>\n",
       "      <td>1480.858640</td>\n",
       "      <td>1799.178761</td>\n",
       "      <td>1593.438455</td>\n",
       "      <td>1390.292206</td>\n",
       "      <td>1503.812537</td>\n",
       "      <td>1376.704527</td>\n",
       "      <td>1352.019634</td>\n",
       "      <td>1475.878843</td>\n",
       "      <td>1369.097328</td>\n",
       "      <td>1333.799042</td>\n",
       "      <td>1454.546540</td>\n",
       "      <td>1468.946383</td>\n",
       "      <td>1363.547294</td>\n",
       "      <td>1467.679097</td>\n",
       "      <td>1479.586828</td>\n",
       "      <td>1553.730654</td>\n",
       "      <td>1511.853498</td>\n",
       "      <td>29455.943022</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>max_direction</td>\n",
       "      <td>1253.192187</td>\n",
       "      <td>1387.041325</td>\n",
       "      <td>1427.620803</td>\n",
       "      <td>1228.497272</td>\n",
       "      <td>1410.537480</td>\n",
       "      <td>1387.486681</td>\n",
       "      <td>1346.043411</td>\n",
       "      <td>1261.335657</td>\n",
       "      <td>1367.359299</td>\n",
       "      <td>1417.358695</td>\n",
       "      <td>1312.008960</td>\n",
       "      <td>1409.489331</td>\n",
       "      <td>1446.229613</td>\n",
       "      <td>1420.323141</td>\n",
       "      <td>1346.464530</td>\n",
       "      <td>1203.901047</td>\n",
       "      <td>1416.536502</td>\n",
       "      <td>1322.958869</td>\n",
       "      <td>1396.544980</td>\n",
       "      <td>1221.830653</td>\n",
       "      <td>26982.760436</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>quantile0.25_direction</td>\n",
       "      <td>1082.619599</td>\n",
       "      <td>1124.478831</td>\n",
       "      <td>1009.327926</td>\n",
       "      <td>1103.599160</td>\n",
       "      <td>1287.247869</td>\n",
       "      <td>1056.706418</td>\n",
       "      <td>1029.563999</td>\n",
       "      <td>1020.000697</td>\n",
       "      <td>1037.679226</td>\n",
       "      <td>1048.744865</td>\n",
       "      <td>974.162965</td>\n",
       "      <td>1025.839320</td>\n",
       "      <td>1187.372287</td>\n",
       "      <td>1033.905105</td>\n",
       "      <td>975.147578</td>\n",
       "      <td>1039.695944</td>\n",
       "      <td>1059.692712</td>\n",
       "      <td>1078.750091</td>\n",
       "      <td>971.977936</td>\n",
       "      <td>993.740281</td>\n",
       "      <td>21140.252811</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>start_hour</td>\n",
       "      <td>260.407804</td>\n",
       "      <td>237.522625</td>\n",
       "      <td>269.146510</td>\n",
       "      <td>328.836951</td>\n",
       "      <td>278.775059</td>\n",
       "      <td>221.573593</td>\n",
       "      <td>246.745325</td>\n",
       "      <td>259.584656</td>\n",
       "      <td>275.235563</td>\n",
       "      <td>238.936644</td>\n",
       "      <td>309.095406</td>\n",
       "      <td>273.398878</td>\n",
       "      <td>281.350268</td>\n",
       "      <td>294.843432</td>\n",
       "      <td>275.071077</td>\n",
       "      <td>278.542869</td>\n",
       "      <td>274.426889</td>\n",
       "      <td>297.011238</td>\n",
       "      <td>306.433893</td>\n",
       "      <td>228.124822</td>\n",
       "      <td>5435.063503</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>mode_direction</td>\n",
       "      <td>251.815216</td>\n",
       "      <td>268.620065</td>\n",
       "      <td>262.225738</td>\n",
       "      <td>182.556133</td>\n",
       "      <td>238.322305</td>\n",
       "      <td>264.363656</td>\n",
       "      <td>288.328284</td>\n",
       "      <td>347.896316</td>\n",
       "      <td>288.736191</td>\n",
       "      <td>231.824613</td>\n",
       "      <td>221.016143</td>\n",
       "      <td>251.564367</td>\n",
       "      <td>199.551714</td>\n",
       "      <td>218.180433</td>\n",
       "      <td>293.960267</td>\n",
       "      <td>221.347204</td>\n",
       "      <td>256.679785</td>\n",
       "      <td>309.275542</td>\n",
       "      <td>302.938450</td>\n",
       "      <td>205.360280</td>\n",
       "      <td>5104.562701</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>min_speed</td>\n",
       "      <td>257.730811</td>\n",
       "      <td>306.668462</td>\n",
       "      <td>228.822819</td>\n",
       "      <td>288.423140</td>\n",
       "      <td>267.343792</td>\n",
       "      <td>140.623594</td>\n",
       "      <td>244.153894</td>\n",
       "      <td>279.412338</td>\n",
       "      <td>188.016772</td>\n",
       "      <td>251.815797</td>\n",
       "      <td>289.713692</td>\n",
       "      <td>222.521174</td>\n",
       "      <td>267.671690</td>\n",
       "      <td>259.269757</td>\n",
       "      <td>306.759697</td>\n",
       "      <td>266.259344</td>\n",
       "      <td>221.609257</td>\n",
       "      <td>283.656586</td>\n",
       "      <td>227.155512</td>\n",
       "      <td>213.476581</td>\n",
       "      <td>5011.104708</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>end_hour</td>\n",
       "      <td>175.733253</td>\n",
       "      <td>215.040497</td>\n",
       "      <td>232.037244</td>\n",
       "      <td>230.387203</td>\n",
       "      <td>225.262290</td>\n",
       "      <td>188.915018</td>\n",
       "      <td>213.807799</td>\n",
       "      <td>204.774562</td>\n",
       "      <td>196.158217</td>\n",
       "      <td>245.444882</td>\n",
       "      <td>263.826086</td>\n",
       "      <td>213.328641</td>\n",
       "      <td>222.148855</td>\n",
       "      <td>260.672628</td>\n",
       "      <td>241.585399</td>\n",
       "      <td>211.835162</td>\n",
       "      <td>245.195675</td>\n",
       "      <td>193.558493</td>\n",
       "      <td>235.886415</td>\n",
       "      <td>220.883505</td>\n",
       "      <td>4436.481823</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>work_days</td>\n",
       "      <td>18.563651</td>\n",
       "      <td>17.260872</td>\n",
       "      <td>19.360629</td>\n",
       "      <td>15.087535</td>\n",
       "      <td>15.640496</td>\n",
       "      <td>14.809761</td>\n",
       "      <td>19.839981</td>\n",
       "      <td>18.562108</td>\n",
       "      <td>12.791859</td>\n",
       "      <td>25.806609</td>\n",
       "      <td>9.228122</td>\n",
       "      <td>26.129770</td>\n",
       "      <td>22.917733</td>\n",
       "      <td>29.133331</td>\n",
       "      <td>23.693618</td>\n",
       "      <td>14.975274</td>\n",
       "      <td>11.282023</td>\n",
       "      <td>10.202352</td>\n",
       "      <td>32.192705</td>\n",
       "      <td>13.079563</td>\n",
       "      <td>370.557993</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>min_direction</td>\n",
       "      <td>4.951553</td>\n",
       "      <td>3.518848</td>\n",
       "      <td>2.599449</td>\n",
       "      <td>10.335722</td>\n",
       "      <td>7.059314</td>\n",
       "      <td>5.605596</td>\n",
       "      <td>4.221212</td>\n",
       "      <td>2.577042</td>\n",
       "      <td>7.384981</td>\n",
       "      <td>3.603500</td>\n",
       "      <td>5.942271</td>\n",
       "      <td>4.822202</td>\n",
       "      <td>5.201068</td>\n",
       "      <td>4.688323</td>\n",
       "      <td>3.356098</td>\n",
       "      <td>4.543015</td>\n",
       "      <td>3.885773</td>\n",
       "      <td>7.554259</td>\n",
       "      <td>6.384762</td>\n",
       "      <td>6.799792</td>\n",
       "      <td>105.034778</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   feature        fold_1        fold_2        fold_3  \\\n",
       "15                  mean_y  19221.398269  14860.651262  18962.502916   \n",
       "46                rec_area  16148.206796  14624.937866  17591.453751   \n",
       "18                   min_y  16284.547346  14276.602778  11824.852361   \n",
       "23                  mode_y  14243.235564  12418.091071  12022.121917   \n",
       "19          quantile0.25_y   8752.418362  11042.226662   9393.385079   \n",
       "21          quantile0.75_y   6075.619293  10397.332364  10132.542047   \n",
       "22                   max_y   7538.338491   8852.231422   9608.756342   \n",
       "20                median_y   7909.615636   8371.098699   9620.838026   \n",
       "44               x_max-min   6342.740038   7107.348223   6685.151519   \n",
       "31      quantile0.75_speed   6020.706322   7530.480071   6843.415336   \n",
       "13                  mode_x   7489.565976   5981.012177   6017.147762   \n",
       "9           quantile0.25_x   6237.476178   6792.530535   5978.948015   \n",
       "45               y_max-min   7701.180483   7015.441758   4979.721939   \n",
       "8                    min_x   6136.728355   6750.891677   6568.348090   \n",
       "30            median_speed   5596.520980   6126.377436   5932.755266   \n",
       "12                   max_x   5444.983737   5362.822399   4658.839087   \n",
       "10                median_x   4917.096823   4762.720295   4761.238827   \n",
       "26               std_speed   5371.017475   4607.418630   4274.091468   \n",
       "16                   std_y   4106.819497   4353.975603   3781.728841   \n",
       "34       nunique_direction   4613.376105   4812.708549   4420.698851   \n",
       "5                   mean_x   5233.628455   4709.286984   5510.496624   \n",
       "11          quantile0.75_x   3953.246604   4288.925463   3787.020570   \n",
       "47                 short_r   3373.485201   3623.217322   4390.631377   \n",
       "48                  long_r   3647.314546   4030.420573   3832.270661   \n",
       "27               var_speed   3480.240342   3629.876909   4246.701165   \n",
       "35          mean_direction   3434.123785   3551.141563   3616.772221   \n",
       "4                nunique_x   3250.615875   3368.575973   3569.579478   \n",
       "6                    std_x   2764.143472   3303.925002   3275.394201   \n",
       "24           nunique_speed   3144.553005   2586.216252   2867.756464   \n",
       "3             work_seconds   2883.292266   2938.462654   3034.911438   \n",
       "41  quantile0.75_direction   2988.695180   2872.318968   2495.881197   \n",
       "32               max_speed   2710.086216   2601.140528   2570.657652   \n",
       "25              mean_speed   2867.696547   2574.062843   2294.608297   \n",
       "17                   var_y   2967.159824   2415.903710   3565.047327   \n",
       "36           std_direction   2471.721913   2270.827548   2229.525009   \n",
       "40        median_direction   2215.969911   2131.537246   2031.313835   \n",
       "33              mode_speed   1911.059255   1764.637195   1831.833440   \n",
       "29      quantile0.25_speed   1617.720344   1834.582400   1794.922871   \n",
       "14               nunique_y   1450.760873   1876.786577   1698.356090   \n",
       "7                    var_x   1720.477449   1648.562638   1445.212246   \n",
       "37           var_direction   1456.635612   1503.958023   1520.379117   \n",
       "42           max_direction   1253.192187   1387.041325   1427.620803   \n",
       "39  quantile0.25_direction   1082.619599   1124.478831   1009.327926   \n",
       "0               start_hour    260.407804    237.522625    269.146510   \n",
       "43          mode_direction    251.815216    268.620065    262.225738   \n",
       "28               min_speed    257.730811    306.668462    228.822819   \n",
       "1                 end_hour    175.733253    215.040497    232.037244   \n",
       "2                work_days     18.563651     17.260872     19.360629   \n",
       "38           min_direction      4.951553      3.518848      2.599449   \n",
       "\n",
       "          fold_4        fold_5        fold_6        fold_7        fold_8  \\\n",
       "15  18740.124450  16064.771306  15829.119294  14643.601725  19059.471628   \n",
       "46  14430.403987  20363.762647  14372.920567  16812.335265  15148.821619   \n",
       "18  13728.388969  11861.664052  11971.266402  13923.519162  12121.415867   \n",
       "23  13743.854767  16278.695224  13677.028194  12072.493242  12569.084161   \n",
       "19  10301.746808   9757.164566   9910.222850  10033.151751  10317.644056   \n",
       "21   8243.777216  11644.253813  11660.845931   5791.399894   9812.241145   \n",
       "22   8773.654795   7743.373998   8690.681684  11767.799492   7076.907906   \n",
       "20   6741.385773   7759.759096   8630.769950  13771.608113   8909.147251   \n",
       "44   6489.086805   6702.366397   7337.931113   7392.554086   8640.621680   \n",
       "31   6496.333151   6779.809631   6852.707523   6714.041764   7693.192412   \n",
       "13   6602.321351   5864.167275   6190.778440   6628.186016   6557.119543   \n",
       "9    6439.180881   6230.616480   6242.351307   6320.322816   6752.132912   \n",
       "45   6828.259983   4791.700611   7861.716167   5560.153491   4762.732641   \n",
       "8    6144.177516   6169.750059   7110.626756   6144.022576   6379.234759   \n",
       "30   5772.127061   5386.196575   5790.936010   5726.561054   5712.461555   \n",
       "12   5339.069990   4244.938606   5602.335646   4507.169634   4780.218619   \n",
       "10   5105.808038   5879.714240   5009.585700   4277.149047   4766.156113   \n",
       "26   4771.584780   4928.447696   5664.363051   5288.767392   4646.308638   \n",
       "16   5018.746880   4298.233037   5229.044141   5888.575181   5444.958164   \n",
       "34   4838.367382   4070.509273   4766.322734   4753.447203   4619.496169   \n",
       "5    5079.473171   4422.662868   4392.881409   4614.913392   4274.149223   \n",
       "11   4656.425009   4640.036751   4062.536589   3824.764374   4541.005955   \n",
       "47   4070.365015   4561.858317   4061.768717   4105.460567   3917.113082   \n",
       "48   4097.307802   3430.549941   3395.159435   3708.116055   4129.041123   \n",
       "27   3992.951837   3225.283808   3016.552031   3389.525165   3834.116966   \n",
       "35   3137.117174   3325.055924   3352.412915   3262.453490   3411.605538   \n",
       "4    3576.186530   3226.801451   3584.189530   3015.056711   3478.292025   \n",
       "6    2842.450496   2995.352464   2658.187859   3309.645727   3043.520326   \n",
       "24   3033.233907   3344.704223   2811.057011   2851.163932   3469.899103   \n",
       "3    2779.552637   2985.616945   2874.812872   3185.932938   3064.172367   \n",
       "41   3134.841245   2636.155692   2788.405260   2394.613832   2748.632388   \n",
       "32   2846.872172   2622.440194   2681.799321   2817.005785   2685.144706   \n",
       "25   2472.872087   2331.352989   2664.881953   2647.635642   2469.498175   \n",
       "17   2575.951206   1550.853741   1608.613683   1814.634462   2523.740648   \n",
       "36   2262.762096   2232.254713   2400.236356   2160.623399   2447.827208   \n",
       "40   2110.706139   2022.628224   2112.166212   2099.945034   1966.265977   \n",
       "33   1897.971950   1944.318107   1835.272233   1913.931482   1803.280317   \n",
       "29   1676.673212   1799.878702   1926.412536   1870.098693   1715.121722   \n",
       "14   1775.311685   1859.571262   1929.057665   1826.406534   1213.983079   \n",
       "7    1696.401233   1337.635802   1605.835699   1317.102904   1767.773950   \n",
       "37   1480.858640   1799.178761   1593.438455   1390.292206   1503.812537   \n",
       "42   1228.497272   1410.537480   1387.486681   1346.043411   1261.335657   \n",
       "39   1103.599160   1287.247869   1056.706418   1029.563999   1020.000697   \n",
       "0     328.836951    278.775059    221.573593    246.745325    259.584656   \n",
       "43    182.556133    238.322305    264.363656    288.328284    347.896316   \n",
       "28    288.423140    267.343792    140.623594    244.153894    279.412338   \n",
       "1     230.387203    225.262290    188.915018    213.807799    204.774562   \n",
       "2      15.087535     15.640496     14.809761     19.839981     18.562108   \n",
       "38     10.335722      7.059314      5.605596      4.221212      2.577042   \n",
       "\n",
       "          fold_9       fold_10       fold_11       fold_12       fold_13  \\\n",
       "15  19220.391557  18907.175236  22768.783831  13362.105250  20717.132446   \n",
       "46  10093.961091  14215.497438  16127.728835  15941.528779  16185.780214   \n",
       "18  11115.969459  16374.271555  13822.706458  13983.270410  13717.698755   \n",
       "23   9054.122054  13618.216230   7770.789793  15906.485680  15011.499135   \n",
       "19  10942.663947   9528.274919  10532.972345   9036.922916   8125.848018   \n",
       "21   9499.975248   8212.246772   9613.107066   8280.914361   6463.666502   \n",
       "22   9858.986677   7961.105068   6230.416604  12278.629486   7357.656086   \n",
       "20   9415.607567   6356.340772   9479.282575   8204.065982   9556.946169   \n",
       "44  10726.021291   7710.675483   6922.813522   6299.975754   5634.520681   \n",
       "31   6162.554779   7507.526844   6770.741541   7159.534025   7383.349319   \n",
       "13   5898.282436   7432.459709   6499.282744   7112.727436   7033.599487   \n",
       "9    7377.456655   6138.372222   7525.964950   5887.438601   6125.348468   \n",
       "45   7348.800399   4100.586790   7325.501805   6596.057998   5863.783078   \n",
       "8    6665.300104   5710.194495   5919.809751   6309.866828   5823.464620   \n",
       "30   6542.476148   6056.271817   6070.806043   5291.572735   6306.944462   \n",
       "12   5098.489258   5837.771945   3575.658281   4247.691465   4899.092854   \n",
       "10   5188.487060   4011.815637   5340.900547   5233.782840   5274.654882   \n",
       "26   4892.011369   4872.977195   5150.068955   5736.877106   4433.948052   \n",
       "16   4923.330188   5878.412545   3221.847193   5429.656796   5820.838737   \n",
       "34   4973.611914   4557.087668   4825.594258   4988.241249   4255.202262   \n",
       "5    4619.674106   4671.836065   4923.838008   4861.315224   4108.480129   \n",
       "11   4837.935149   4666.870425   4389.777884   3752.735032   4766.758192   \n",
       "47   5331.023129   4165.795555   3961.757058   3892.548725   4001.802667   \n",
       "48   4043.938609   5135.184760   3847.820889   4233.901501   4188.840190   \n",
       "27   3238.870922   3556.896721   3332.906741   4403.268924   3968.402835   \n",
       "35   3544.490806   3336.431234   3646.296857   3018.330051   3562.101904   \n",
       "4    3475.652348   3295.418592   3056.181372   3131.639666   3492.966779   \n",
       "6    2957.962580   3092.647234   3670.153818   2872.652138   3094.026340   \n",
       "24   2639.104191   2956.480185   3012.789462   3128.888741   3083.397729   \n",
       "3    3066.513438   2815.307183   2932.914103   2754.064598   2850.194614   \n",
       "41   2809.864794   2986.432662   2802.381491   2928.465170   3072.117707   \n",
       "32   2353.869498   2608.549061   2622.193070   2560.998042   2705.537846   \n",
       "25   2428.629190   2364.523276   2492.599495   2371.829634   2626.113960   \n",
       "17   2465.660272   2210.519442   3259.763836   1802.444003   1901.253924   \n",
       "36   2158.416797   2115.478504   2218.454371   2453.766945   2329.622222   \n",
       "40   2045.043413   2032.264054   1905.752172   2152.513408   1870.592374   \n",
       "33   1893.956273   1905.202804   1750.462897   1881.669068   1796.612452   \n",
       "29   1886.736387   1855.301220   1850.186606   1604.645197   1793.787791   \n",
       "14   1711.705474   1603.780799   1334.876210   1605.519021   1507.037705   \n",
       "7    1663.034179   1957.063299   1525.435207   1523.418578   1283.888964   \n",
       "37   1376.704527   1352.019634   1475.878843   1369.097328   1333.799042   \n",
       "42   1367.359299   1417.358695   1312.008960   1409.489331   1446.229613   \n",
       "39   1037.679226   1048.744865    974.162965   1025.839320   1187.372287   \n",
       "0     275.235563    238.936644    309.095406    273.398878    281.350268   \n",
       "43    288.736191    231.824613    221.016143    251.564367    199.551714   \n",
       "28    188.016772    251.815797    289.713692    222.521174    267.671690   \n",
       "1     196.158217    245.444882    263.826086    213.328641    222.148855   \n",
       "2      12.791859     25.806609      9.228122     26.129770     22.917733   \n",
       "38      7.384981      3.603500      5.942271      4.822202      5.201068   \n",
       "\n",
       "         fold_14       fold_15       fold_16       fold_17       fold_18  \\\n",
       "15  15412.060062  18132.757549  14357.078150  16131.053514  14225.209955   \n",
       "46  14364.157745  18263.158126  15755.966707  16738.530806  13690.274764   \n",
       "18  11954.141218  15572.038331  13169.232998  15972.488351  12181.050149   \n",
       "23  12242.712079  12351.150072  15816.506679  12944.195955   9756.646410   \n",
       "19  11397.262519   7700.081598   9817.452248   9872.390371  10180.992647   \n",
       "21  10150.285330   9349.578912   8743.799586  10094.495908  11550.560815   \n",
       "22  14054.804534  10386.944431   9044.114166   6993.588445  11768.278314   \n",
       "20   6610.683051   8762.884358   8557.135417   8461.190984   9256.224817   \n",
       "44   9408.699651   7338.287897   7021.278338   7430.697060   8032.359884   \n",
       "31   7429.278060   6142.983239   6307.850238   7802.956958   6621.741121   \n",
       "13   6552.546623   5741.005855   6809.196062   7826.107415   5974.635742   \n",
       "9    6010.735019   7402.675412   7260.485944   6044.042175   6903.171291   \n",
       "45   6536.727297   5825.743214   6647.009286   5979.615541   7270.051269   \n",
       "8    6015.045934   6310.960961   6017.172016   5876.697282   6278.309280   \n",
       "30   5987.531710   5789.582407   5613.650844   5006.616581   5745.779769   \n",
       "12   5639.182695   5680.992464   4273.834286   6169.282135   5556.057816   \n",
       "10   4491.051563   4881.292127   5807.160314   4529.264288   5503.335942   \n",
       "26   4612.147752   4952.727953   4493.533755   4828.241296   4832.819964   \n",
       "16   4044.069201   3767.843959   4651.530424   4538.891367   6042.356184   \n",
       "34   5025.045166   4307.181990   5005.232801   4488.435013   4994.210842   \n",
       "5    3813.747782   3664.791033   4105.334844   4972.660301   4165.869482   \n",
       "11   4963.888117   3494.570440   4761.220887   3247.339275   4586.739466   \n",
       "47   4030.984821   4035.829349   3960.724818   3713.429572   4019.502079   \n",
       "48   3380.788650   3416.731911   4471.965511   4596.110208   3859.619137   \n",
       "27   3721.163911   3829.276306   3431.717232   3134.958234   4440.574301   \n",
       "35   3216.504201   3203.040713   3172.409158   3314.408409   3125.365224   \n",
       "4    2731.642838   3477.105487   3522.261010   3574.411092   3216.194085   \n",
       "6    3000.678668   3747.655587   3435.756100   2931.367602   3013.391407   \n",
       "24   3394.117942   3076.607195   3073.557331   2921.273090   3135.721985   \n",
       "3    2759.144754   2844.696748   2850.358745   2861.042388   2670.687298   \n",
       "41   2717.107565   2884.510980   2898.809423   3170.038454   2844.801728   \n",
       "32   2973.308424   2674.703581   2929.943658   2771.789661   2294.952996   \n",
       "25   2620.586293   2540.634811   2354.461126   2356.248281   2501.276690   \n",
       "17   2005.892018   1383.743518   2653.610326   2353.463178   2218.921993   \n",
       "36   2317.674479   2508.857475   2249.989114   2034.669956   2245.553846   \n",
       "40   2116.245086   2096.200213   2048.873735   2040.028182   2273.373324   \n",
       "33   1602.763286   1739.450006   1973.866690   2017.343105   1983.783619   \n",
       "29   1574.623400   1568.130046   2076.063536   1456.512684   1736.126246   \n",
       "14   1757.717653   1759.637455   2013.877045   1422.531158   1795.152181   \n",
       "7    1518.160794   1554.616567   1470.336309   1497.242814   1546.934406   \n",
       "37   1454.546540   1468.946383   1363.547294   1467.679097   1479.586828   \n",
       "42   1420.323141   1346.464530   1203.901047   1416.536502   1322.958869   \n",
       "39   1033.905105    975.147578   1039.695944   1059.692712   1078.750091   \n",
       "0     294.843432    275.071077    278.542869    274.426889    297.011238   \n",
       "43    218.180433    293.960267    221.347204    256.679785    309.275542   \n",
       "28    259.269757    306.759697    266.259344    221.609257    283.656586   \n",
       "1     260.672628    241.585399    211.835162    245.195675    193.558493   \n",
       "2      29.133331     23.693618     14.975274     11.282023     10.202352   \n",
       "38      4.688323      3.356098      4.543015      3.885773      7.554259   \n",
       "\n",
       "         fold_19       fold_20     importance  \n",
       "15  18949.921438  17959.295079  347524.604919  \n",
       "46  13328.244559  18088.551947  312286.223509  \n",
       "18  14749.631402  14921.924357  273526.680381  \n",
       "23  15072.394317  13075.354771  259644.677316  \n",
       "19   7367.890286   7511.275000  191521.986946  \n",
       "21   6821.680726   9105.177010  181643.499938  \n",
       "22   7035.937205   6844.425595  179866.630740  \n",
       "20   9386.376649  11216.928896  176977.889781  \n",
       "44   8006.215924   7319.645719  148548.991065  \n",
       "31   7315.837474   7689.653699  139224.693506  \n",
       "13   7849.353640   7542.144354  133601.640043  \n",
       "9    5822.463126   6886.417008  130378.129994  \n",
       "45   6247.824854   4215.546815  123458.155420  \n",
       "8    5388.811534   5423.793193  123143.205787  \n",
       "30   6002.184760   5840.165143  116297.518356  \n",
       "12   4980.503252   4606.847297  100505.781466  \n",
       "10   5940.142820   4029.915400   99711.272504  \n",
       "26   4681.385145   4810.684742   97849.422413  \n",
       "16   7170.819490   3028.979388   96640.656814  \n",
       "34   4576.711529   4563.491455   93454.972410  \n",
       "5    4943.636102   5021.909314   92110.584513  \n",
       "11   3821.290833   5032.774015   86075.861029  \n",
       "47   3902.511237   3349.462622   80469.271228  \n",
       "48   3595.862345   3618.829447   78659.773295  \n",
       "27   4177.322925   4368.016906   74418.624182  \n",
       "35   3615.632190   3345.370991   67191.064348  \n",
       "4    3239.925103   3583.364864   66866.060809  \n",
       "6    3207.703943   2904.176704   62120.791667  \n",
       "24   3026.648647   2783.914212   60341.084606  \n",
       "3    2917.383128   2816.664931   57885.726044  \n",
       "41   2800.362294   2723.824411   56698.260445  \n",
       "32   2832.764646   2679.069385   53542.826441  \n",
       "25   2502.790651   2671.879712   50154.181652  \n",
       "17   2230.952595   2722.145142   46230.274847  \n",
       "36   2151.759388   2157.388158   45417.409499  \n",
       "40   1809.552658   2301.965619   41382.936815  \n",
       "33   1892.509751   2014.210035   37354.133964  \n",
       "29   1670.183395   1570.754896   34878.461885  \n",
       "14   1510.560309   2165.986406   33818.615181  \n",
       "7    1636.483177   2088.758599   31804.374812  \n",
       "37   1553.730654   1511.853498   29455.943022  \n",
       "42   1396.544980   1221.830653   26982.760436  \n",
       "39    971.977936    993.740281   21140.252811  \n",
       "0     306.433893    228.124822    5435.063503  \n",
       "43    302.938450    205.360280    5104.562701  \n",
       "28    227.155512    213.476581    5011.104708  \n",
       "1     235.886415    220.883505    4436.481823  \n",
       "2      32.192705     13.079563     370.557993  \n",
       "38      6.384762      6.799792     105.034778  "
      ]
     },
     "execution_count": 165,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "feature_importances['importance'] = feature_importances[[i for i in feature_importances.columns if i != 'feature']].apply(lambda x: x.sum(), axis=1)\n",
    "feature_importances.sort_values(by='importance',ascending=False, inplace=True)\n",
    "feature_importances"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 166,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['work_days', 'min_direction']"
      ]
     },
     "execution_count": 166,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "NotimportantFeats = list(feature_importances['feature'][-2:])\n",
    "NotimportantFeats"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 混淆矩阵"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 167,
   "metadata": {},
   "outputs": [],
   "source": [
    "#!/usr/bin/env python\n",
    "# _*_ coding:utf-8 _*_\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "def plot_Matrix(cm, classes, title=None,  cmap=plt.cm.Blues):\n",
    "    plt.rc('font',family='Times New Roman',size='8')   # 设置字体样式、大小\n",
    "    \n",
    "    # 按行进行归一化\n",
    "    cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]\n",
    "    print(\"Normalized confusion matrix\")\n",
    "    str_cm = cm.astype(np.str).tolist()\n",
    "    for row in str_cm:\n",
    "        print('\\t'.join(row))\n",
    "    # 占比1%以下的单元格，设为0，防止在最后的颜色中体现出来\n",
    "    for i in range(cm.shape[0]):\n",
    "        for j in range(cm.shape[1]):\n",
    "            if int(cm[i, j]*100 + 0.5) == 0:\n",
    "                cm[i, j]=0\n",
    "\n",
    "    fig, ax = plt.subplots()\n",
    "    im = ax.imshow(cm, interpolation='nearest', cmap=cmap)\n",
    "    # ax.figure.colorbar(im, ax=ax) # 侧边的颜色条带\n",
    "    \n",
    "    ax.set(xticks=np.arange(cm.shape[1]),\n",
    "           yticks=np.arange(cm.shape[0]),\n",
    "           xticklabels=classes, yticklabels=classes,\n",
    "           title=title,\n",
    "           ylabel='Actual',\n",
    "           xlabel='Predicted')\n",
    "\n",
    "    # 通过绘制格网，模拟每个单元格的边框\n",
    "    ax.set_xticks(np.arange(cm.shape[1]+1)-.5, minor=True)\n",
    "    ax.set_yticks(np.arange(cm.shape[0]+1)-.5, minor=True)\n",
    "    ax.grid(which=\"minor\", color=\"gray\", linestyle='-', linewidth=0.2)\n",
    "    ax.tick_params(which=\"minor\", bottom=False, left=False)\n",
    "\n",
    "    # 将x轴上的lables旋转45度\n",
    "    plt.setp(ax.get_xticklabels(), rotation=45, ha=\"right\",\n",
    "             rotation_mode=\"anchor\")\n",
    "\n",
    "    # 标注百分比信息\n",
    "    fmt = 'd'\n",
    "    thresh = cm.max() / 2.\n",
    "    for i in range(cm.shape[0]):\n",
    "        for j in range(cm.shape[1]):\n",
    "            if int(cm[i, j]*100 + 0.5) > 0:\n",
    "                ax.text(j, i, format(int(cm[i, j]*100 + 0.5) , fmt) + '%',\n",
    "                        ha=\"center\", va=\"center\",\n",
    "                        color=\"white\"  if cm[i, j] > thresh else \"black\")\n",
    "    fig.tight_layout()\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 168,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Normalized confusion matrix\n",
      "0.8781925343811395\t0.07269155206286837\t0.04911591355599214\n",
      "0.0283775447254781\t0.8846391116594695\t0.08698334361505243\n",
      "0.01031873423526714\t0.042650768172437514\t0.9470304975922953\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAARoAAAEdCAYAAADTtqgCAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAZUUlEQVR4nO3dd3xUdbrH8c8z6UxAiqiAsiqIAiIWXLuIdCxItXLtiGXt9ep6VUS9ul7rrqxd2bXgiii6awMB26qggoJSVsArVvBuMplASDLP/WMGFNaEgP44M+z3/XrlxZzMZPJwSD5z5pyZg7k7IiIhxaIeQEQ2fwqNiASn0IhIcAqNiASn0IhIcAqNiASXH/UADZFXGPdYSdOox8gpMYP227UgFtNjyYZIpVIYEMvLi3qUnJOqrWXOxx8tc/eW616XE6GJlTQlv9s5UY+RU0oLnecfHEW8tHHUo+SUZEWCgrwYpVpvG6yiIsF2Wzdb8lPX6eFORIJTaEQkOIVGRIJTaEQkOIVGRIJTaEQkOIVGRIJTaEQkOIVGRIJTaEQkOIVGRIJTaEQkOIVGRIJTaEQkOIVGRIJTaEQkOIVGRIJTaEQkOIVGRIJTaEQkOIVGRIJTaEQkOIVGRIJTaEQkOIVGRIJTaEQkOIVGRIJ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ZbCIBKfQiEhwCo2IBKfQiEhwCo1sEDM7xMyWmNlUM3vWzIo38GuvyVy+q47bbG9mh27o/Ul2U2hkY4xz90NIn+1tKKTfRLkhpyxw99/UcdX2QINCI7lDrwyWn+ND4Fkz6wm0AY43szNJhyIFnOLui83sQdLvcF8C/C+Amb3h7gea2QHAzaTf3zOW9DuVDzCz/dy9Z+aEYuu9P8lu2qKRn+NgYB4w3937kD53SpvM1s7ZwBVm9mvSL9brBfzjJ+5j9akiegBPkX638rhMZLpsxP1JFtIWjWyMEZktkbmkz/w2M/P5jsAhZjY1s/wVsCPwQWZ5JrDfunfm7ssyf6bWefa1Ufcn2UehkY0xzt2vAsjsjF19prd5wMur979kztezJ+lzBAPs8RP35WbWwt2XZ05gXk36THIbe3+ShfTUSX4x7j4L+DpzROo10ie2egcoMrPJQIef+LIrgEmZ2w8jfa6aA8zsyY28P8lCeq+TiASnLRoRCU6hEZHgFBoRCU6hEZHgFBoRCU6hEZHgFBoRCU6hEZHg/h+CZOrb07E/IgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_Matrix(cms,classes=['ci', 'wei', 'tuo'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 测试集预测保存"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 169,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2000 \n",
      " 拖网    1250\n",
      "围网     480\n",
      "刺网     270\n",
      "Name: predict, dtype: int64\n",
      "        ID predict\n",
      "8942  7000      围网\n",
      "8256  7001      拖网\n",
      "8027  7002      围网\n",
      "7458  7003      拖网\n",
      "7124  7004      围网\n"
     ]
    }
   ],
   "source": [
    "#投票策略筛选预测结果\n",
    "submit = []\n",
    "for line in cv_pred:\n",
    "    submit.append(np.argmax(np.bincount(line)))\n",
    "\n",
    "#预测结果\n",
    "res = test[['ID']]\n",
    "res['predict'] = submit\n",
    "res['predict'] = res['predict'].map(label2type)\n",
    "\n",
    "print(len(res), '\\n',res.predict.value_counts())\n",
    "print(res.sort_values('ID').head())\n",
    "\n",
    "#保存模型\n",
    "res.sort_values('ID').to_csv('../output/'+filename+'_submission.csv', index=False, header=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Draft"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
